Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

call Powershell in VBS with parameters

I need one, simple thing. I am using VBS to call Powershell and I like to execute it with parameter (variable from VBS)

Dim Input

Input = InputBox("Enter User's alias to check")
Set objShell = CreateObject("Wscript.Shell")

objShell.run("powershell.exe -noexit -file .\ps_v2.ps1") &Input

As you see it is pretty short and easy code, PS_v2.ps1 works fine when executed in PS console directly with argument. I need variable Input to be used as parameter.

In PS console i just type

.\ps_V2.ps1 Input

and it works. So it must be somewhere in ObjShell.run. When I used echo just to check if the variable is assigned correctly i got a correct output.

Result is that PowerShell window appear just for a second and disappear. I think it is not taking "Input" in consideration at all.

So make long story short. How should look the VBS line to call PS script with argument? Just like ".\ps_V2.ps1 Input" in PS console.

Thanks a lot in advance!

Edited: 19.2.2014 - 16:32 Thank You Ekkehard.Horner, works fine

like image 587
user3328316 Avatar asked Oct 28 '25 16:10

user3328316


1 Answers

The concatenation (&) is at the wrong palce:

Set objShell = CreateObject("Wscript.Shell") objShell.run("powershell.exe -noexit -file .\ps_v2.ps1") &Input

Set objShell = CreateObject("Wscript.Shell") objShell.run("powershell.exe -noexit -file .\ps_v2.ps1 " & Input)
like image 170
Ekkehard.Horner Avatar answered Oct 31 '25 12:10

Ekkehard.Horner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!