简体   繁体   English

使用 PowerCLI 从 VM 检索实时信息

[英]Retrieving real time info from VM's with PowerCLI

I have a couple of lines in a script that are giving me an issue:我在脚本中有几行给我一个问题:

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

When running this I receive this as output:运行时,我收到 output:

Operation is not valid due to the current state of the object.
At :line:0 char:0

If the second line is run a few seconds after the connection to vCenter is made I receive the output I expect.如果在连接到 vCenter 后几秒钟运行第二行,我会收到预期的 output。 What I believe is happening is that my connection to vCenter hasn't completed before my second line has started.我认为正在发生的事情是,在我的第二条线路开始之前,我与 vCenter 的连接尚未完成。 I am not sure of the best way to wait for or what to check for in a completed connection.我不确定等待的最佳方式或在完成的连接中检查什么。

you might try using start-sleep command in PS您可以尝试在 PS 中使用 start-sleep 命令

http://technet.microsoft.com/en-us/library/ee177002.aspx http://technet.microsoft.com/en-us/library/ee177002.aspx

however -- as with all "sleep" functions, this isn't necessarily the best way to fix a timing problem as your pushback never may never account for all possible latency issues.但是 - 与所有“睡眠”功能一样,这不一定是解决计时问题的最佳方法,因为您的回退可能永远无法解决所有可能的延迟问题。

a better solution would be to test for the completion of a command (and I'm not sure how to do that with the VMWare CLI)更好的解决方案是测试命令是否完成(我不确定如何使用 VMWare CLI 执行此操作)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM