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

前端 未结 2 604
攒了一身酷
攒了一身酷 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条回答
  •  猫巷女王i
    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
    

提交回复
热议问题