4

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

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Confirmed, works fine. In my case the PS command required a forward slash ./ps_v2.ps1 and the script required the param($Input). This allows to take advantage and use/apply backwordlooking Regex patterns not available in VBscript and still run 'old' VBscripts matured over the years.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.