4 Replies Latest reply on Jun 26, 2013 7:21 AM by Sami Halonen

    Running Powershell using BSA

    Sami Halonen

      I'm testing some very simple Powershell "scripts" with BSA and I'm getting somewhat confusing results. I hope someone could help me out a bit here.


      First question, is there a better (or more proper) way to run any scripts on a target server other than packaging the script, deploying it to a server and then using post-command to run it? Currently I'm making a blpackage out of the script and then run it with a post command "powershell.exe -ExecutionPolicy Bypass -File <scriptName.ps1>


      If I put "whoami" or "Stop-Service Spooler -Force -Verbose" in my one-line script I get the expected results. I'm testserver\bladelogicrscd and my  print spooler service stops. However, the script gets stuck and powershell.exe wont exit. The job is stuck until I manually kill powershell.exe


      But.. if I put Start-Service Spooler -Verbose in my one-liner, the whole thing gets stuck even before print spooler is started and I get no output whatsoever from the script.


      What am I doing wrong?

        • 1. Re: Running Powershell using BSA
          Paul Seager-Smith

          Hi Sami,


          Your method is probably the simplest way to handle Powershell scripts. You can then push the script down as part of the package and then run it immediately afterwards. If you so wish, you can also use an NSH script that runs and creates the Powershell script on the fly before running it, but it depends what you are trying to achieve.


          Your problem with th script hanging is due to an API issue with Powershell, which means that it does not always handle input correctly when called via an API (as BSA does). To fix this, try adding the argument "-InputFormat none" to your powershell command. This should help.


          If you search for this on the forums, there is another posting somewhere that links to an article explaining why this is the case, but I don't have it to hand at the moment.






          • 2. Re: Running Powershell using BSA
            Siddu angadi

            Use the NSHScripting Job.


            Please refer the below link:






            • 3. Re: Running Powershell using BSA
              Bill Robinson

              you should not need to use the job post- command here - you can create an 'external command' in the blpackage and put your commands in there as if you were running from the cmd prompt, w/ the -inputformat NONE that paul mentions.


              you can also use a nsh script job, but that would mean echoing the powershell script contents into a file, and then calling nexec, then removing the file. 

              1 of 1 people found this helpful
              • 4. Re: Running Powershell using BSA
                Sami Halonen

                Thank you guys, -InputFormat None solved the problem. I tried looking thru the forums for some time, but couldn't find a solution.