BlackHawk-VM
Contributor
Contributor

Help with STATS script

Using this line of code:

Get-VM MyVMsName | Get-Stat -stat cpu.usage.average, mem.usage.average, disk.usage.average, net.usage.average -IntervalMins 60

Is there any way of not having the output truncate the timestamp?

On two digit days it adds "..." instead of "AM" or "PM"

cpu.usage.average 7/10/2008 12:00:0... 4.43 %

cpu.usage.average 7/9/2008 12:00:00 AM 4.1 %

Thx;

Greg

Tags (1)
0 Kudos
4 Replies
LucD
Leadership
Leadership

Could it be that the VI Toolkit format-table is not loaded in your session ?

This file defines the Timestamp column as 20 characters wide for LongSampleImpl object (which is what Get-Stat is returning).

You could try the Update-FormatData cmdlet and let it point to the .ps1xml file in the VIToolkitForWindows folder.

From what shell are you running the Get-Stat cmdlet ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

BlackHawk-VM
Contributor
Contributor

That seems to be a pretty good clue.

Unfortunately to hold a date such as: "12/10/2008 12:00:00 AM" you would need 22 bytes, so while you pegged where the problem lied it still exists.

So to work around this I have resorted to piping the output to the following:

| Format-Table -Property MetricId, Value, Unit, Timestamp -AutoSize

Now if someone can set that up so I can have the value and unit concatenated (Value + " " + Unit) I would probably be close to a good report.

Thx;

Greg

0 Kudos
admin
Immortal
Immortal

So to work around this I have resorted to piping the output to the following:

| Format-Table -Property MetricId, Value, Unit, Timestamp -AutoSize

You can do that last part with a select. Pipe what you've got into: | select metricid, timestamp, @{N="Value"; E={$_.Value + $_.Unit}}

BlackHawk-VM
Contributor
Contributor

That certainly helped!

I used the following due to the number/string issue in the expression:

| Select-Object -property MetricId, Timestamp, @{Name="Value"; Expression={[string]$_.Value + " " + $_.Unit}}

Thanks for everyone's help.

Greg

EDIT: Note that the last part is Expression={"open square bracket" string "close square bracket] $_.Value + " " + $_.Unit}}

Message was edited by: BlackHawk-VM

0 Kudos