我在脚本中有几行给我一个问题:
Connect-VIServer "test-vcenter.test.com" -User user -Password pass
Get-VM -Name "test-vm" | Get-Stat -Stat cpu.ready.summation -Realtime | Select-Object -First 1 value | Format-List
运行此程序时,我将其作为输出接收:
Operation is not valid due to the current state of the object.
At :line:0 char:0
如果在连接到 vCenter 后几秒钟运行第二行,我会收到我期望的输出。我认为正在发生的事情是,在我的第二条线路开始之前,我与 vCenter 的连接尚未完成。我不确定等待的最佳方式或在完成的连接中检查什么。