Reply to Message

View discussion in a popup

Replying to:
LucD
Leadership
Leadership

You can add a Where-clause and use an array of datastore you don't want to see in the report.

Datacenter is possible, for cluster you need to check if the datastore is visible on all ESXi nodes in the cluster to start with.

The calculation for the number of of powered on and powered off VMs was incorrect.

The new version

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

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

$undesiredDatastores = @('DS1','DS2')

$report=Get-Datastore |

where{$undesiredDatastores -notcontains $_.Name} |

Select Name,

    @{N='Datacenter';E={

        $parent = Get-View $_.ExtensionData.Parent

        while($parent -isnot [VMware.Vim.Datacenter]){

            $parent = Get-View -Id $parent.Parent

        }

        $parent.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 $_.ExtensionData.VM -Property RunTime | where{$_.Runtime.PowerState -eq 'poweredon'}).Count}},

    @{N='NumVMOff';E={@(Get-View -Id $_.ExtensionData.VM -Property RunTime | where{$_.Runtime.PowerState -eq '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