简体   繁体   English

VMWare vSphere Powercli Get-Stat在某些主机上不起作用

[英]VMWare vSphere Powercli Get-Stat does not work on some host

I'm trying to do some capacity planning on my VMWare host and would like to extract cpu/memory stats for each host. 我正在尝试在我的VMWare主机上进行一些容量计划,并希望为每个主机提取cpu /内存统计信息。

I'm able to run a command such like this: 我能够运行这样的命令:

PowerCLI C:\> Get-VMHost -Name "192.168.1.14" |Get-Stat -Stat mem.usage.average -Start (Get-Date).AddDays(-1) -Finish (Get-Date)

and it displays the stats. 并显示统计信息。

But then I pick another host, such as 192.168.1.15 and it doesn't work, ending with this error: 但是然后我选择了另一个主机,例如192.168.1.15 ,它不起作用,并以以下错误结尾:

Get-Stat : 2015-06-23 10:56:45    Get-Stat        Object reference not set to an instance of an object.
At line:1 char:42
+ Get-VMHost -Name "192.168.1.15" |Get-Stat <<<<  -Stat mem.usage.average -Start (Get-Date).AddDays(-1) -Finish (Get-Date)
    + CategoryInfo          : NotSpecified: (:) [Get-Stat], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats

The command Get-VMHost -Name "192.168.1.15" works. 命令Get-VMHost -Name "192.168.1.15"有效。

Any idea? 任何想法?

PowerCli 5.0.1
VMWare ESX 5.0 Update 3
vCenter 5.0.0 Build 1300600

I think the issue you are having is the Date object being passed to the cmdlet Get-Stat . 我认为您遇到的问题是将Date对象传递给cmdlet Get-Stat From the error it appears to be treating the date as an object? 从错误似乎将日期视为对象? According to the documentation that supported input for -Start and -Finish is "dd/mm/yyyy". 根据支持-Start-Finish输入的文档为“ dd / mm / yyyy”。

Try this instead 试试这个

Get-Stat -Stat mem.usage.average -Start ((Get-Date).AddDays(-1)).ToString("dd/MM/yyyy") -Finish (Get-Date -Format "dd/mm/yyyy")

For -Start we need to do date calculation before we convert to string. 对于-Start我们需要转换为字符串之前进行日期计算。 .ToString("dd/MM/yyyy") is one method of doing it. .ToString("dd/MM/yyyy")是一种实现方法。 Since you are using today for the -Finish we can just use -Format from Get-Date to get the string without complication. 由于您今天使用的是-Finish我们可以仅使用Get-Date -FormatGet-Date字符串而无需复杂化。

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

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