2

I need to start a powershell script from C# and get the PSSSecurityException on pipeline.Invoke()

AuthorizationManager check failed.

My code:

RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
using (Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration))
{
    runspace.Open();
    Pipeline pipeline = runspace.CreatePipeline();
    Command scriptCommand = new Command(scriptfile);
    pipeline.Commands.Add(scriptCommand);
    pipeline.Invoke();
}

Questions

  1. I suspect that I need to set PSCredential. But I can not promt for it, so I have to handle this in code. Can this be done in a secure way? (This was not the case)

2 Answers 2

2

Check out this SuperUser post: https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts

You probably just need to allow unsigned scripts to run. In the PS console, type the following:

set-executionpolicy remotesigned

Another resource echoes this: http://tgnp.me/2011/09/powershell-authorizationmanager-check-failed-resolution/

Give that a try and let me know what happens.

To capture the output from the script, try this:

Collection output = pipeline.Invoke();
foreach (PSObject psObject in output)
{
    <here you can ToString the psObject for the output and write it line by line to your log>
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your input, I could use the part about printing the output, the part about "AuthorizationManager check failed." was related to another problem with my environment. I have figured it out now and will post the solution for others that run into the same problem.
1

The problem was that the script was placed on a share. To run scripts on this share I needed to add the share to Trusted Sites.

enter image description here

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.