【发布时间】:2015-12-08 17:22:29
【问题描述】:
我目前在尝试多线程部署虚拟机(特别是 VMWare)时遇到问题,我正在使用以下代码进行尝试:
connect-viserver vcenter
for($i=251; $i -le 261; $i++) {
Start-Job {Param([string]$num) New-vm -ResourcePool Storage-POCs -Name "virtual-machine-$num" -vm "newvm" -Datastore MyDataStore} -ArgumentList $i
}
这是我当前从该代码进入终端的输出:
HasMoreData : True
StatusMessage :
Location : localhost
Command : Param([string]$num)
New-vm -ResourcePool Storage-POCs -Name "virtual-machine-$num" -vm "newvm" -Datastore MyDataStore
JobStateInfo : Running
Finished : System.Threading.ManualResetEvent
InstanceId : 3a6b8f27-c8d8-4386-9e58-6c1dfcfef52c
Id : 419
Name : Job419
ChildJobs : {Job420}
Output : {}
Error : {}
Progress : {}
Verbose : {}
Debug : {}
Warning : {}
State : Running
HasMoreData : True
StatusMessage :
Location : localhost
Command : Param([string]$num)
New-vm -ResourcePool Storage-POCs -Name "virtual-machine-$num" -vm "newvm" -Datastore MyDataStore
JobStateInfo : Running
...
谁能告诉我为什么 $num 不是转换成 $i 的数字吗?
谢谢, 亚历克斯
【问题讨论】:
-
工作不工作了吗?确定没有翻译?我认为作业的输出不会显示替换。
-
我做了一个小测试;它工作正常。我认为您可能会将
Start-Job的输出与作业本身的输出混淆:9|%{Start-Job{param([string]$num) "~$num~"}-ArgumentList $_}|Wait-Job|Receive-Job -
你是对的。实际命令的输出很好。看到Start-Job的输出,没想到去查。
标签: powershell parameters arguments powercli start-job