简体   繁体   中英

How to pass ADS (Arguments with dynamic strings) which can have spaces from VBscript to Powershell

I wanted to know if it is possible to pass arguments to powershell via VBscript.

Here is my code and my investigation on this topic so far.

VBscript:

Dim pathvalue (pathvalue will dynamic path, which may have spaces in it. lets say path is "\\Server\search\File in some folder\Stack Overflow\")
sCmd = "powershell.exe -ExecutionPolicy ByPass -noexit -File \\server\Support\abhishek\Automation\SearchUtility.ps1 -Inputs " & PathValue
Set oShell = CreateObject("Wscript.Shell")
iResult = oShell.Run(sCmd, 1, true)

PS1.

Param([String] $Inputs)
$FolderPath = $Inputs;
echo "$FolderPath";

Expected result :

\\\\Server\\search\\File in some folder\\Stack Overflow\\

Actual Result :

\\\\Server\\search\\File

I tried different methods to pass the arguments ex. by putting it in single quotes, by putting 3 double Quotes but still it is not working.

Here is a code example:

sCmd = "powershell.exe -ExecutionPolicy ByPass -noexit -File \\\\server\\Support\\abhishek\\Automation\\SearchUtility.ps1 -Inputs " &"'" & PathValue & "'"

I got stuck for days and I haven't found a way to get this done. I need some help here. (I am new to Powershell)

Thanks in advance.

Try this. You don't need to build it in steps like this. I just did it this way to make it more readable. The last line is the critical part.

sCmd = "powershell.exe -ExecutionPolicy ByPass -noexit "
sCmd = sCmd & "-File \\server\Support\abhishek\Automation\SearchUtility.ps1 "
sCmd = sCmd & "-Inputs " & Chr(34) & PathValue & Chr(34)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM