none
Running hidden power shell RRS feed

  • Question

  • I am trying to run a script, and I can't have a powershell window pop up for it.  I am trying to use the -WindowStyle Hidden when starting, but it is not working for me.  I am using Win7 x64.

    To test, I hit Win + R, and in the Run box, I type:  powershell -WindowStyle Hidden my_script.ps1

    And when I hit Enter, Powershell window pops up. 

    If I try to just run powershell.exe -WindowStyle Hidden

    without any script, a new powershell window pops up, and then disappears.  I can see in the task manager that it is still running, so I guess it is hidden eventually..  but it still opened a window initially.

    How do I run a powershell script without a powershell widow opening at all?

    Thanks!

    Wednesday, April 7, 2010 1:38 AM

Answers

All replies

  • Seems simple, but apparently it isn't.

    It seems that PowerShell basically opens the console screen *before* it evaluates all of the arguments.  So the console opens, the arguments are evaluated and the console hides itself if the appropriate arguments are passed.

    I haven't been able to come up with something that completely hides the PowerShell console 100% and I can't remember seeing a solution that does.

    Wednesday, April 7, 2010 2:00 AM
    Moderator
  • I had the same problem and found only 2 solutions:

    1. use VBScript
    2. create custom WinForm application
    I wasn't able to get it working using just the switches like -WindowStyle :|
    Wednesday, April 7, 2010 6:01 AM
  • Seems simple, but apparently it isn't.

    It seems that PowerShell basically opens the console screen *before* it evaluates all of the arguments.  So the console opens, the arguments are evaluated and the console hides itself if the appropriate arguments are passed.

    I haven't been able to come up with something that completely hides the PowerShell console 100% and I can't remember seeing a solution that does.


    Yep, I was wondering if I was doing something wrong, but I guess that is what powershell does.  The problem with this in my case is that the script is called automatically as a user logs in, and thus the script window can hang around for a while, as other programs start and user-login related events occur. 

    I think I am going to try this program:  http://www.ntwind.com/software/utilities/hstart.html  I have used it before in my XP builds, back in the PS 1.0 days, I am guessing it will still work with PS 2.0.

    Wednesday, April 7, 2010 6:50 PM
  • I had the same problem and found only 2 solutions:

    1. use VBScript
    2. create custom WinForm application
    I wasn't able to get it working using just the switches like -WindowStyle :|

    Thanks, that indeed seems to be the easiest solution!

    Wednesday, April 7, 2010 6:53 PM

  • Thank you for sharing the solution. It’s very useful.

    Regards


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, April 12, 2010 11:09 AM
  • You can also run it as a task and check the "Run whether the user is logged in or not". That should run the PowerShell script without opening a window.
    Sunday, December 2, 2012 4:43 PM