Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Powershell from vbs with command as parameter

Hey i want to run from an vbs script a powershell commando. Something like start powershell.exe and enter a specific command like Restart-Service. I thought something similar to this could 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)

Has someone an idea how can i manage this?

like image 478
Alesfatalis Avatar asked Jul 12 '12 09:07

Alesfatalis


2 Answers

1) store your powershell command as powershell script.
2) Use the vbs to run the powershell

  Set objShell = CreateObject("Wscript.Shell")
 objShell.Run("powershell.exe -noexit c:\scripts\test.ps1")
like image 153
HariHaran Avatar answered Sep 20 '22 01:09

HariHaran


Try this:

powershell -command '& {command to run}'

/G

like image 35
Gisli Avatar answered Sep 20 '22 01:09

Gisli