Running Powershell from vbs with command as parameter

Hi, I want to run powershell command from vbs script. Something like start powershell.exe and enter a specific command, for example Restart-Service. I thought something like this might work:

strCommand = "C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -command Restart-Service [service name]" Set WshShell = WScript.CreateObject("WScript.Shell") Set objExec = WshShell.Exec(strCommand) 

Does anyone have an idea how I can do this?

+4
source share
3 answers

1) save the powershell command as a powershell script.
2) Use vbs to start powershell

  Set objShell = CreateObject("Wscript.Shell") objShell.Run("powershell.exe -noexit c:\scripts\test.ps1") 
+2
source

Try the following:

 powershell -command '& {command to run}' 

/ G

+3
source

Try the following:

 Set objShell = CreateObject("Wscript.Shell") objShell.Run("powershell.exe -noexit .\c:\scripts\test.ps1") 

Or save the files in the same folder where exex is located, and then

 Objshell.Run("powershell.exe -noexit .\test.ps1") 
0
source

All Articles