none
How to Execute a PowerShell Script with no Window RRS feed

  • Question

  • I have a powershell script that I need to run silently.  The script will be called many times while using an application so a DOS window appearing and disappearing would be very distracting.  Is it possible to run a powershell shell script in the background so the user is unaware?  
     

    Tuesday, February 16, 2010 4:12 PM

Answers

  • You need to wrap it in either an executable or a vbscript.  The vbscript method is the quickest:

    Dim shell,command
    command = "powershell.exe -nologo -command ""dir c:\users\ttanasovski\scripts\*.* |out-file c:\users\ttanasovski\scripts\test.txt"""
    Set shell = CreateObject("WScript.Shell")
    shell.Run command,0


    Tuesday, February 16, 2010 10:01 PM
  • There is also a -windowstyle parameter that can be set to "Hidden"
    Tuesday, February 16, 2010 4:18 PM
    Moderator

All replies

  • Does this do what you want?

    powershell -noninteractive <script>

    Tuesday, February 16, 2010 4:17 PM
    Moderator
  • There is also a -windowstyle parameter that can be set to "Hidden"
    Tuesday, February 16, 2010 4:18 PM
    Moderator

  • Thank you mjolinor-

    I have tried both switches -noninteractive and -windowstyle hidden and both present a DOS window for a short period of time.  What I really need is not to have anything appear when the script runs.  Your help is greatly appreciated.

    Any other suggestions?

    Tuesday, February 16, 2010 9:18 PM
  • Not yet, but that might change.
    Tuesday, February 16, 2010 9:42 PM
    Moderator
  • I had the same problem some time ago. I ended up with a custom application that runs a script with no window because it is created as a WinForm exe. For more info read the post: Run scheduled tasks with WinForm GUI in PowerShell .
    Tuesday, February 16, 2010 9:53 PM
  • You need to wrap it in either an executable or a vbscript.  The vbscript method is the quickest:

    Dim shell,command
    command = "powershell.exe -nologo -command ""dir c:\users\ttanasovski\scripts\*.* |out-file c:\users\ttanasovski\scripts\test.txt"""
    Set shell = CreateObject("WScript.Shell")
    shell.Run command,0


    Tuesday, February 16, 2010 10:01 PM
  • Tome,

    Thanks!  This seems to do the trick - Thanks again.
    Wednesday, February 17, 2010 3:49 PM
  • I think the words "no Window" in the question didn't mean "briefly open a window and then hide it because you know he shouldn't have seen it"...
    Wednesday, May 16, 2018 10:11 AM