0

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
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • Does `Get-VMHost -Name "192.168.1.14" | Get-Stat -Memory | ? { $_.metricid -like "mem.usage.average" }` output that statistic? – Etan Reisner Jun 23 '15 at 15:11

1 Answers1

0

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

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..ToString("dd/MM/yyyy") is one method of doing it. Since you are using today for the -Finish we can just use -Format from Get-Date to get the string without complication.

Matt
  • 45,022
  • 8
  • 78
  • 119