I'm trying to do some capacity planning on my VMWare host and would like to extract cpu/memory stats for each host.
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:
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.
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
. 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".Try this instead
For
-Start
we need to do date calculation before we convert to string..ToString("dd/MM/yyyy")
is one method of doing it. Since you are using today for the-Finish
we can just use-Format
fromGet-Date
to get the string without complication.