Powershell Script inside C# RRS feed

  • Question

  • I am trying to add a UI to some automation that runs PowerShell Scripts. 

    I am able to get this working when I am running in Visual Studio. But when I deploy it, it apparently quits the Using block after on the PowerShellInstance.AddScript(script); line. Then ofcourse, it doesn't run the powershell script. Why do you think it might be doing this when deployed only and not having any issues on running it from VS? Here is the snippet that I have issues with:

                    using (PowerShell PowerShellInstance = PowerShell.Create())
                        string script = "Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted; Get-ExecutionPolicy";




    Thanks very much, Manoj Deshpande.

    Tuesday, January 2, 2018 10:38 PM

All replies

  • This should be posted in the VS C# forum and not here.

    Hint:  You are missing a catch block.

    What do you expect to happen?  The code will execute but produces no results or output.


    • Edited by jrv Tuesday, January 2, 2018 10:51 PM
    Tuesday, January 2, 2018 10:50 PM
  • I will repost in that forum, thanks! I sure do have a catch block. It doesn't get into that either. It goes to the code line after that. 

    Thanks very much, Manoj Deshpande.

    Tuesday, January 2, 2018 10:53 PM
  • That can only happen when you have a broken or mismatched closure but I doubt that this is happening as I have never seen that get past the C# compiler.  It is more likely that the code is executing with no error that is trappable or it is executing with no output.

    I suppose a corrupt system could cause this but that seems odd.


    Tuesday, January 2, 2018 11:00 PM