如何将 VBscript 中可以有空格的 ADS(带动态字符串的参数)传递给 Powershell

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

我想知道是否可以通过 VBscript 将参数传递给 powershell。

这是我的代码和到目前为止我对此主题的调查。

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";

预期结果:

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

实际结果:

\Server\search\File

我尝试了不同的方法来传递参数 ex。通过将它放在单引号中,通过放置 3 个双引号但仍然不起作用。

这是一个代码示例:

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

我被困了好几天了,我还没有找到完成这件事的方法。我需要一些帮助。 (我是 Powershell 的新手)

提前致谢。

试试这个。您不需要按这样的步骤构建它。我只是这样做以使其更具可读性。最后一行是关键部分。

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