How can I run a powershell script as a background task without displaying a window?

前端 未结 2 583
攒了一身酷
攒了一身酷 2020-12-28 16:30

I\'m working on creating a script that will fire off performance counters and store them in a .csv file, rolling over when the file gets too big. Running the script from a p

相关标签:
2条回答
  • 2020-12-28 17:06
    Powershell.exe -windowstyle hidden -file C:\iis_test.ps1
    

    But when you run this command, a CMD window will appear.
    However, you can use VBscript instead

    Set objShell = CreateObject("WScript.Shell")
    objShell.Run "CMD /C START /B " & objShell.ExpandEnvironmentStrings("%SystemRoot%") & "\System32\WindowsPowerShell\v1.0\powershell.exe -file " & "YourScript.ps1", 0, False
    Set objShell = Nothing
    
    0 讨论(0)
  • 2020-12-28 17:16

    try this from a DOS/CMD shell:

    powershell.exe -windowstyle hidden -file C:\iis_test.ps1
    
    0 讨论(0)
提交回复
热议问题