I have a VBscript file. I run this VBscript using CScript on windows 2012 server. The VBscript runs fine on the server.
But I need to call this VBScript file from Powershell. This is what I did.
For simplicity, this is what I have in my VBscript file
echo.vbs
Msgbox("hello world")
I wrote the test.ps1
$acommand = "C:\Windows\System32\Cscript.exe C:\deleteit\echo.vbs"
Invoke-Expression $acommand
PS C:\> c:\windows\system32\cscript.exe c:\deleteit\echo.vbsc:\windows\system32\cscript.exe c:\deleteit\echo.vbsInvoke-Expression(iex) should generally be avoided, because it can be a security risk and because better solutions are usually available. Direct invocation, as shown in js2010's answer, is the right approach; see this answer for additional information.