LucD
Leadership
Leadership

Try something like this.

#poweshell script to query the datastores and send an e-mail for any over 90%

connect-viserver '<server>' -User '<user>' -Password '<password>'

$report=Get-Datastore |

Select Name,

    @{N='TotalSpaceGB';E={[math]::Round($_.CapacityGB,0)}},

    @{N='UsedSpaceGB';E={[math]::Round($_.CapacityGB - $_.FreeSpaceGB,0)}},

    @{N='UsedSpace%';E={[math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100,0)}},

    @{N='ProvisionedSpaceGB';E={[Math]::Round(($_.CapacityGB - $_.FreeSpaceGB + $_.ExtensionData.Summary.Uncommitted/1GB),0)}},

    @{N='AmountOverprovisionedGB';E={[Math]::Round($_.ExtensionData.Summary.Uncommitted/1GB $_.FreeSpaceGB,0)}},

    @{N='NumVMOn';E={@(Get-View -Id $_.VM -Property RunTime -Filter @{'Runtime.PowerState'='poweredon'}).Count}},

    @{N='NumVMOff';E={@(Get-View -Id $_.VM -Property RunTime -Filter @{'Runtime.PowerState'='poweredoff'}).Count}} |

Where{$_.'UsedSpace%' -ge 90} |

Sort-Object -Property Name |

Export-Csv -Path z:\datastoresize.csv -NoTypeInformation -UseCulture

$reportHtml = $report | ConvertTo-Html | Out-String

Send-MailMessage -To<email> -Subject DataStore_Usage_Over_90% `

  -SmtpServer <relay>-From <from> `

  -BodyAsHtml -Body $reportHtml -Attachments z:\datastoresize.csv


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

Reply
0 Kudos