管道选择时,PowerCLI不会等待

时间:2018-04-02 18:41:50

标签: powershell

我对Select别名有疑问。

我的脚本正在获取一个VM列表,其中包含启动它们的get-vm,然后只选择Name值。

如果我保持" |选择姓名"在cmdlet中,脚本输出无序,如下所示。当我删除选择时,无论查询有多大,它都按顺序执行。这是为什么?

示例:

Connect-VIServer vcenter

$myvm=Read-Host "Enter the VM name or names using wildcards to update"

write-host "VM's to update: " 
get-vm $myvm | Where-Object {($_.powerstate -eq "PoweredOn")}

write-host "Exiting without action"

上面的结果会返回我的预测结果" Test * vm"",然后是消息"退出无动作"

Enter the VM name or names using wildcards to update: test*
VM's to update: 
Name                 PowerState Num CPUs MemoryGB       
----                 ---------- -------- --------       
TestServer01         PoweredOn  1        4.000          
Test-ServerB         PoweredOn  1        4.000          
Exiting without action

但是,当我添加选择名称时,请使用以下代码:

Connect-VIServer vcenter

$myvm=Read-Host "Enter the VM name or names using wildcards to update"

write-host "VM's to update: " 
get-vm $myvm | Where-Object {($_.powerstate -eq "PoweredOn")} |select Name

write-host "Exiting without action"

我的结果现在显示了vm结果之前的最后一个写主机命令。

Enter the VM name or names using wildcards to update: test*
VM's to update: 

Exiting without action
Name           
----           
TestServer01
Test-ServerB

0 个答案:

没有答案