hi folks,
just getting started with PowerCLI and have pieced together a scipt to email me a list of snapshots (I realize there are many pre-canned scripts that do this). the script works as intended, but the SizeMB variable includes 19-20 decimal places which makes it a little hard to read.
scirpt line in question:
$Report = get-vm | get-snapshot | select vm,powerstate,name,sizemb | ConvertTo-Html -head $a | Out-String
sample output:
VM | PowerState | Name | SizeMB |
Test Cluster | PoweredOff | Before Installing Drivers | 432.1879596710205078125 |
MAX-DEV | PoweredOn | 3-6-2013 | 5201.38588237762451171875 |
full script below. can someone suggest an easy way to round or truncate the snapshot size to an integer?
Thank you,
alex
add-pssnapin VMware.VimAutomation.Core
Connect-VIServer foo.bar.com
$vCenterSettings = Get-View -Id 'OptionManager-VpxSettings'
$MailSender = ($vCenterSettings.Setting | Where-Object { $_.Key -eq "mail.sender"}).Value
$MailSmtpServer = ($vCenterSettings.Setting | Where-Object { $_.Key -eq "mail.smtp.server"}).Value
$a = "<style>"
$a = $a + "BODY{font-family: Verdana, Arial, Helvetica, sans-serif;font-size:11;font-color: #000000}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color: #04B45F}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color: #BCF5A9}"
$a = $a + "</style>"
$Report = get-vm | get-snapshot | select vm,powerstate,name,sizemb | ConvertTo-Html -head $a | Out-String
Send-MailMessage -from $MailSender -to "me@foo.bar.com" -subject "SoE vCenter Snapshot Report" -body $Report -BodyAsHtml -smtpServer $MailSmtpServer
Exit
Try changing this line
$Report = get-vm | get-snapshot | select vm,powerstate,name,sizemb | ConvertTo-Html -head $a | Out-String
into this
$Report = get-vm | get-snapshot | select vm,powerstate,name,@{N="sizemb";E={[math]::Round($_.SizeMb,2)}} |
ConvertTo-Html -head $a | Out-String
With a calculated property you can do calculations or modifications on the property you want to display
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try changing this line
$Report = get-vm | get-snapshot | select vm,powerstate,name,sizemb | ConvertTo-Html -head $a | Out-String
into this
$Report = get-vm | get-snapshot | select vm,powerstate,name,@{N="sizemb";E={[math]::Round($_.SizeMb,2)}} |
ConvertTo-Html -head $a | Out-String
With a calculated property you can do calculations or modifications on the property you want to display
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hi LucD,
That worked, thanks for the thoughtful and timely response, this calculated property is exactly what I needed.
Much apprecaited,
alex
After LucD got me going in the right direction, I added a column for snapshot age and sort function to list by snapshot size:
$Report = get-vm | get-snapshot | select vm,powerstate,name,@{Name="Age Days";Expression={((Get-Date)-$_.Created).Days}},@{N="Size MB";E={[math]::Round($_.SizeMb,0)}} | sort "Size MB" -Descending | ConvertTo-Html -head $a | Out-String