Powershell call in VBS with parameters

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

Dim input

Input = InputBox ("Enter the user alias to verify")
   Set objShell = CreateObject ("Wscript.Shell")

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

As you can see, this is quite short and simple code, PS_v2.ps1 works fine when launched directly from the PS console with an argument. I need variable input to be used as a parameter.

In the PS console, I just type

. \ ps_V2.ps1 Login

and it works. So it should be somewhere in ObjShell.run. When I used the echo only to verify the correct assignment of a variable, I got the correct result.

The result is that the PowerShell window only appears for a second and disappears. I think it does not accept "Input" at all.

So make the long story short. How should I look for a VBS string to call a PS script with an argument? Just like ". \ Ps_V2.ps1 Login" in the PS console.

Many thanks!

Edited: 02/19/2014 - 16:32 Thanks Ekkehard.Horner, works great

+3
source share
1 answer

Concatenation (&) is in the wrong place:

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)
+2
source

All Articles