【发布时间】:2021-02-05 09:56:29
【问题描述】:
我正在尝试在 Visual Build 中的一个项目步骤之间调用一个 powershell 脚本。 我在可视化构建中创建了一个新脚本,并调用了我的 powershell 脚本。 我选择了 vbscript,这是脚本中的代码:
Dim paths, source1
paths = "C:\Dev\"
source1 = "\\10.156.3.14\win"
sCmd = "powershell.exe -noexit -ExecutionPolicy Unrestricted -file C:\Dev\downloadfiles.ps1 -target """ & paths & """ -source """ & source1 & """"
Set xShell = CreateObject("Wscript.Shell")
rReturn = xShell.Run(sCmd, 0, true)
脚本使我的构建超时。
通过控制台运行时,powershell 脚本运行良好。 我有什么遗漏吗?
download.files.ps1 参数:
param (
[string[]]$target,
[string[]]$source
)
此外,还有什么方法可以让我在控制台运行时看到它的输出。即使使用“-noexit”,我什么也看不到。
更新 -- 脚本的第一部分运行并返回一些相关文件。 虽然接受参数的部分不起作用。
这似乎是更好的选择,因为脚本现在正在接受参数:
Set objShell = CreateObject("Wscript.Shell")
objShell.run("powershell.exe -noexit -ExecutionPolicy Unrestricted -file .\downloadfiles.ps1 -target """ & paths & """ -source """ & source1 & """")
跟进问题。我将如何通过 vbscript 调用传入一个字符串数组? 例如
$target = @('c:\dev','d:\lib')
【问题讨论】:
-
PowerShell 将以逗号分隔的单词列表解释为参数上下文中的字符串数组:
-target 'c:\dev','c:\lib' -
我在 vbscript
paths = "'C:\Dev\', 'C:\new\'" Set objShell = CreateObject("Wscript.Shell") objShell.run("powershell.exe -noexit -ExecutionPolicy Unrestricted -file .\downloadfiles.ps1 -target """ & paths & """ -source """ & source1 & """")中尝试过,但在 powershell 中的测试路径检查失败 -
我们还没有收到您的来信.. 我的回答解决了您的问题吗?如果是这样,请通过单击左侧的大复选标记图标
✓考虑accepting。这将帮助其他有类似问题的人更轻松地找到它。
标签: powershell vbscript visual-build-professional