I'm a beginner to powershell. I have a custom cmdlet I created. This code will break at the last line:
RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
PSSnapInException psEx = null;
runspaceConfiguration.AddPSSnapIn(mySnapin, out psEx);
using (Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
{
runspace.Open(); // breaks here.
It gives me Access to registry is not allowed error, unless I enclose the above code inside:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
});
To access the SPSecurity, I have to of course bring in my references: Microsoft.Sharepoint. It actually works, but my powershell code has nothing to do with sharepoint. Is there a more general powershell security dll that I can use instead of the SPSecurity (even though it works)? I can't find one. thanks.