excel 将多个目录传递到PowerShell

7jmck4yq  于 2023-05-01  发布在  Shell
关注(0)|答案(1)|浏览(113)

我想运行PowerShell脚本并通过参数传递工作目录。
我现在在VBA中的代码:

strCommand = "powershell.exe -noexit -ExecutionPolicy Bypass -command Start-Process -Verb RunAs powershell.exe -file  `\" &  scriptfolder  & "`\"" output `\""" & sFolder & "`\"" -corefolder `\""" &  Dfd_core & "`\"" -configfolder `\""" &  Dfd_Root & "`\"" -sheetfolder `\""" & dfdsheet & "`\""" 
Set WsShell = CreateObject("WScript.Shell")
WsShell.Run (strCommand)

我在PowerShell中的代码:

param([String]$output, [String]$corefolder, [String]$configfolder, [String]$sheetfolder)

所有参数(output、corefolder、configfolder和sheetfolder)都是用户选择的位置或目录,因此它们可以在其中包含空格。

k97glaaz

k97glaaz1#

您需要在脚本中嵌入双引号并转义内部的双引号。此外,我认为您实际上希望将这三个参数传递给PowerShell脚本,而不是Start-Process命令。试试这个:

<code>strCommand = "powershell.exe -noexit -ExecutionPolicy Bypass -command Start-Process -Verb RunAs powershell.exe -file  `"" &amp;  scriptfolder  &amp; "`\""" &amp; output &amp; "`\"" -corefolder `\""" &amp;  Dfd_core &amp; "`\"" -configfolder `\""" &amp;  Dfd_Root &amp; "`\"" -sheetfolder `\""" &amp; dfdsheet &amp; "`\"""  Set WsShell = CreateObject("WScript.Shell") WsShell.Run (strCommand)
</code>

相关问题