1

Through the use of several code snippets here and in VMware's website, I've created the following code that works:

Connect-ViServer server
$body = Get-Folder -name vm | Get-VM | Get-Snapshot | Select Name, VM, SizeMb, Created | Out-String 
send-mailmessage -From "myemail.com" -To "myemail.com" -SmtpServer "myserver.com" -Body $body -Subject "Snapshot Report"

The output that I get from this looks like this:

Name                VM                       SizeMB Created            
----                --                       ------ -------            
snapshot name       server       ...3507232666015625 11/6/2013 11:53...
snapshot name       server       ...4918060302734375 11/6/2013 10:30...
snapshot name       server...    ...0483551025390625 11/6/2013 10:32:...
snapshot name       server       ...2000579833984375 11/6/2013 3:58:34 PM

I figure there has to be a way to format the output to where it will accurately show the size in megabytes with a max of just 3 decimals and display the entire time created. My problem I know is somewhere here:

| Select Name, VM, SizeMb, Created | out-string

Does anyone know how to format output from Select in order to specify just a max of 2-3 digit decimals?

1 Answer 1

2

You can use a format string in a calculated property to limit the output to two digits. You can also use the -AutoSize (or simply -a) parameter of the Format-Table cmdlet to correct the column widths. Complete example:

$body = Get-Folder -name vm | Get-VM | Get-Snapshot | Select Name, VM, @{name='SizeMb';expression={'{0:0.00}' -f $_.SizeMb}}, Created | Out-String

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .