Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 175326

vmware powershell

$
0
0

I have this query that I want to send out an email for anything that is used at a certain percentage. I want to add Free Space as well as % for Used space and then alert on the % of used space that is > 90%. I was hoping to also add a section on the script were certain datastores could be added so they are ignored (ones we know about and don't care ). I also want to have an email sent if there query returns nothing with the subject like - no datastores over 90% usage. Any help is greatly appreciated - I have the gist of what I want but I am not sure how to build in the logic

 

#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| SelectName,@{N="TotalSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity)/1GB,0)}},@{N="UsedSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace)/1GB,0)}},@{N="ProvisionedSpaceGB";E={[Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,0)}},@{N=”AmountOverprovisionedGB”;E={[Math]::Round(($_.ExtensionData.Summary.Uncommitted – $_.ExtensionData.Summary.FreeSpace)/1GB,0)}},@{N="NumVMOn”;E={@($_ | Get-VM| where{$_.PowerState -eq"PoweredOn"}).Count}},@{N="NumVMOff”;E={@($_ | Get-VM| where{$_.PowerState -nq"PoweredOn"}).Count}} | SortName | Export-Csv-Pathz:\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


Viewing all articles
Browse latest Browse all 175326

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>