Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running powershell from VBScript with Arguments 2

Status
Not open for further replies.

woter324

Technical User
Jan 26, 2007
179
GB
Hi All,

I've written a powershell script that takes arguments. The PS script is executed and arguments are passed from a VBScript.

I am having problems working out the correct format of the command line. I am nearly there, but at the moment it returns:
Code:
Organizational unit "xxx.xxxxx.co.uk/Company" was not found. Please make sure you have typed it correctly.

The correct OU would be "xxx.xxxxx.co.uk/Company Name/All Users"

The code that executes is:
Code:
strCreateUser = strAlias & " " & chr(34) & strOU & Chr(34) & " " & strFN & " " & strLN & " " & chr(34) & strDB & Chr(34)

strCMD="Powershell -noexit -command " & chr(34) & "& {" &oFile.ShortPath & " " & strCreateUser & "}" & chr(34)

objShell.run "Powershell -noexit -command " & chr(34) & "&{" &oFile.ShortPath & " " & strCreateUser & "}" & chr(34)
.

All though I've put in the quotes, they don't seem to work.

I've read the powershell /? help but I am still confused.

If anybody could point me in the right direction, I'd be very grateful.

Many thanks

Woter
 
Sorted it. Needed to change the double-quotes for single-quotes. i.e. from Chr(34) to chr(39)

For example:

Code:
Set oFile=fso.GetFile(strScriptPath)

strCreateUser = strAlias & " " & chr(39) & strOU & Chr(39) & " " & strFN & " " & strLN & " " & chr(39) & strDB & Chr(39)

objShell.run "Powershell -noexit -command " & chr(34) & "&{" &oFile.ShortPath & " " & strCreateUser & "}" & chr(34),,True


HTH
 
A star from me Woter, thanks for sharing. I am playing with this kind of integration too.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top