locked
Bat file to run PS1 file quietly RRS feed

  • Question

  • I have a .bat file that starts a powershell script. the powershell script sends a list to my mailbox. What I want is to get the .bat file run without any DOS pop up windows.
    Tuesday, November 27, 2012 9:37 AM

Answers

  • What's the context for the problem you're trying to solve?

    The reason I ask is that Blindrood gave you the best answer possible given your specification of running from a batch file. There are other options, depending on the situation and your reason for eliminating the console window. As a few examples:

    - if you simply want to prevent interaction with the script, just running it as Blindrood suggests.

    - if you run the file by clicking on something yourself, instead of using a batch file you can use a Windows shortcut with the options Blindrood mentions, and set the shortcut to run with a minimized window - this ensures that the initial console-mode application spawn window starts minimized.

    - if this is a task triggered by a time or other event, you can tell the Task Scheduler to run the script hidden. This will ensure that you never see any popup window, even momentarily, even in the task bar.

    • Proposed as answer by jrv Tuesday, November 27, 2012 4:50 PM
    • Marked as answer by IamMred Thursday, December 6, 2012 4:52 AM
    Tuesday, November 27, 2012 2:09 PM

All replies

  • powershell.exe /?

    suggest: -noninteractive -windowstyle hidden


    • Edited by Blindrood Tuesday, November 27, 2012 9:43 AM
    Tuesday, November 27, 2012 9:42 AM
  • DOS Window still pops up.

    Tuesday, November 27, 2012 9:53 AM
  • What's the context for the problem you're trying to solve?

    The reason I ask is that Blindrood gave you the best answer possible given your specification of running from a batch file. There are other options, depending on the situation and your reason for eliminating the console window. As a few examples:

    - if you simply want to prevent interaction with the script, just running it as Blindrood suggests.

    - if you run the file by clicking on something yourself, instead of using a batch file you can use a Windows shortcut with the options Blindrood mentions, and set the shortcut to run with a minimized window - this ensures that the initial console-mode application spawn window starts minimized.

    - if this is a task triggered by a time or other event, you can tell the Task Scheduler to run the script hidden. This will ensure that you never see any popup window, even momentarily, even in the task bar.

    • Proposed as answer by jrv Tuesday, November 27, 2012 4:50 PM
    • Marked as answer by IamMred Thursday, December 6, 2012 4:52 AM
    Tuesday, November 27, 2012 2:09 PM
  • DOS Window still pops up.

    Not DOS, but a console window. To work around this, you can execute your script using ps1ex32 or ps1exe64, which can run a PowerShell script silently. For example:


    ps1exe32 -s 0 "C:\Scripts\My Script.ps1" arg1 [arg2 [...]]

    Bill

    • Proposed as answer by Bill_Stewart Thursday, November 29, 2012 9:44 PM
    Tuesday, November 27, 2012 3:19 PM