Hi,
I would like to get the report via email for only Datastore Cluster summary report like Datastores cluster Name| Total Capacity| Used Space| Free% | .
Datastores cluster Name | Total Capacity | Used Space | Free%|
I tried below script but it is providing all Datastores Space report, i need only DS cluster Summary
$report = foreach($vc in $global:DefaultVIServers){
Get-Datastore -Server $vc |
where {($_.FreeSpaceGB/$_.CapacityGB) -le 0.15} |
Select @{N='vCenter';E={$vc.Name}},
@{N='Datacenter';E={$_.Datacenter.Name}},
@{N='DSC';E={Get-DatastoreCluster -Datastore $_ -Server $vc | Select -ExpandProperty Name}},
Name,CapacityGB,
@{N='FreespaceGB';E={[math]::Round($_.FreespaceGB,2)}},
@{N='Freespace%';E={[math]::Round($_.FreespaceGB/$_.CapacityGB*100,1)}},
@{N='ProvisionedSpaceGB';E={
[math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted)/1GB,2)}},
@{N='UnCommittedGB';E={[math]::Round($_.ExtensionData.Summary.Uncommitted/1GB,2)}},
@{N='VM';E={$_.ExtensionData.VM.Count}}
}
$report | Export-Csv report.csv -NoTypeInformation -UseCulture
Thanks
Ranjith
Try something like this
Get-DatastoreCluster -Server $vc |
Select @{N = 'vCenter'; E = {$vc.Name}},
@{N = 'Datacenter'; E = {(Get-Datastore -RelatedObject $_ | select -First 1).Datacenter.Name}},
@{N = 'DSC'; E = {$_.Name}},
CapacityGB,
@{N = 'FreespaceGB'; E = {[math]::Round($_.FreespaceGB, 2)}},
@{N = 'Freespace%'; E = {[math]::Round($_.FreespaceGB / $_.CapacityGB * 100, 1)}},
@{N = 'ProvisionedSpaceGB'; E = {
[math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / 1GB, 2)}
},
@{N = 'UnCommittedGB'; E = {[math]::Round($_.ExtensionData.Summary.Uncommitted / 1GB, 2)}},
@{N = 'VM'; E = {((Get-View -Id $_.ExtensionData.ChildEntity).VM.Count | Measure-Object -Sum).Sum}}
}
$sMail = @{
To = 'you@my.domain'
From = 'me@my.domain'
Subject = 'DatastoreCluster Report'
BodyAsHtml = $true
Body = $report | ConvertTo-Html | Out-String
SmtpServer = 'mailserver.my.domain'
}
Send-MailMessage @sMaiL
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Get-DatastoreCluster -Server $vc |
Select @{N = 'vCenter'; E = {$vc.Name}},
@{N = 'Datacenter'; E = {(Get-Datastore -RelatedObject $_ | select -First 1).Datacenter.Name}},
@{N = 'DSC'; E = {$_.Name}},
CapacityGB,
@{N = 'FreespaceGB'; E = {[math]::Round($_.FreespaceGB, 2)}},
@{N = 'Freespace%'; E = {[math]::Round($_.FreespaceGB / $_.CapacityGB * 100, 1)}},
@{N = 'ProvisionedSpaceGB'; E = {
[math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / 1GB, 2)}
},
@{N = 'UnCommittedGB'; E = {[math]::Round($_.ExtensionData.Summary.Uncommitted / 1GB, 2)}},
@{N = 'VM'; E = {((Get-View -Id $_.ExtensionData.ChildEntity).VM.Count | Measure-Object -Sum).Sum}}
}
$sMail = @{
To = 'you@my.domain'
From = 'me@my.domain'
Subject = 'DatastoreCluster Report'
BodyAsHtml = $true
Body = $report | ConvertTo-Html | Out-String
SmtpServer = 'mailserver.my.domain'
}
Send-MailMessage @sMaiL
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is Works like a Cham... Now i need small modification
If possible
1. Need to Get the Report in TB
2. Get the Report only when datastore goes Below 20% free. If space is above 20% free not required to add in the report.
Thanks in Advance.
Try like this
Get-DatastoreCluster -Server $vc |
where {($_.FreeSpaceGB / $_.CapacityGB) -le 0.2} |
Select @{N = 'vCenter'; E = {$vc.Name}},
@{N = 'Datacenter'; E = {(Get-Datastore -RelatedObject $_ | select -First 1).Datacenter.Name}},
@{N = 'DSC'; E = {$_.Name}},
CapacityGB,
@{N = 'FreespaceTB'; E = {[math]::Round($_.FreespaceGB / 1KB, 2)}},
@{N = 'Freespace%'; E = {[math]::Round($_.FreespaceGB / $_.CapacityGB * 100, 1)}},
@{N = 'ProvisionedSpaceTB'; E = {
[math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / 1TB, 2)}
},
@{N = 'UnCommittedTB'; E = {[math]::Round($_.ExtensionData.Summary.Uncommitted / 1TB, 2)}},
@{N = 'VM'; E = {((Get-View -Id $_.ExtensionData.ChildEntity).VM.Count | Measure-Object -Sum).Sum}}
}
$sMail = @{
To = 'you@my.domain'
From = 'me@my.domain'
Subject = 'DatastoreCluster Report'
BodyAsHtml = $true
Body = $report | ConvertTo-Html | Out-String
SmtpServer = 'mailserver.my.domain'
}
Send-MailMessage @sMaiL
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I Am getting email with only 20% free space. But when i ran the script, getting below error.
Attempted to divide by zero.
At C:\temp\DatastoreClusterReport1.ps1:18 char:11
+ where {($_.FreeSpaceGB / $_.CapacityGB) -le 0.2} |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
Thanks
Ranjith
Do you have a datastorecluster without any datastores in it?
We can avoid those
Get-DatastoreCluster -Server $vc |
where {$_.CapacityGB -ne 0 -and ($_.FreeSpaceGB / $_.CapacityGB) -le 0.2} |
Select @{N = 'vCenter'; E = {$vc.Name}},
@{N = 'Datacenter'; E = {(Get-Datastore -RelatedObject $_ | select -First 1).Datacenter.Name}},
@{N = 'DSC'; E = {$_.Name}},
@{N = 'CapacityTB'; E = {[math]::Round($_.CapacityGB / 1KB, 2)}},
@{N = 'FreespaceTB'; E = {[math]::Round($_.FreespaceGB / 1KB, 2)}},
@{N = 'Freespace%'; E = {[math]::Round($_.FreespaceGB / $_.CapacityGB * 100, 1)}},
@{N = 'ProvisionedSpaceTB'; E = {
[math]::Round(($_.ExtensionData.Summary.Capacity - $_.Extensiondata.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / 1TB, 2)}
},
@{N = 'UnCommittedTB'; E = {[math]::Round($_.ExtensionData.Summary.Uncommitted / 1TB, 2)}},
@{N = 'VM'; E = {((Get-View -Id $_.ExtensionData.ChildEntity).VM.Count | Measure-Object -Sum).Sum}}
}
$sMail = @{
To = 'you@my.domain'
From = 'me@my.domain'
Subject = 'DatastoreCluster Report'
BodyAsHtml = $true
Body = $report | ConvertTo-Html | Out-String
SmtpServer = 'mailserver.my.domain'
}
Send-MailMessage @sMaiL
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes there are some DSC.. Now its working fine but again only capacity still coming as GB, is it possible to change TB
vCenter | Datacenter | DSC | CapacityGB | FreespaceTB | Freespace% | ProvisionedSpaceTB |
Thanks
Forgot that one, fixed above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc.
Good day.
Well and wish the same.
The below script working fine to me but i need to sort by free-space by descending order to give the alert to concern team.
Please Advise.
Thanks in advance
$connection = Connect-VIServer
# The HTML style
$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style += "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style += "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style += "TD{border: 1px solid black; padding: 5px; }"
$style += "</style>"
# The used percentage font colors
$fontGreen = '1FC533'
$fontYellow = 'E9C10F'
$fontOrange = 'EE772E'
$fontRed = 'E50000'
# The email body
$body = '<p>These are all the VMware ESXi datastores available in VCenter. If any volumes are colored yellow, orange, or red,
please take action as needed like adding space to the respective SAN volume, deleting unnecessary files, or shuffle files around
to free up space.</p>'
$body += "<p>
<font color='$fontGreen'>Green</font> = Used percentage between 0% and 70%<br/>
<font color='$fontYellow'>Yellow</font> = Used percentage between 70% and 90%<br/>
<font color='$fontOrange'>Orange</font> = Used percentrage between 90% and 95%<br/>
<font color='$fontRed'>Red</font> = Used percentage between 95% and 100%
</p>"
# Get the datastore info and place it into the email body
$body += Get-Datastore |
# Select the columns to display
Select @{N='Datastore';E={
# Used percentage
$script:p = [math]::Round(($_.CapacityGB - $_.FreeSpaceGB)/$_.CapacityGB*100,1)
# Used percentage between 0% and 70% is green
if($p -lt 70){"#fg#$($_.Name)#fe#"}
# Used percentage between 70% and 90% is yellow
elseif($p -lt 90){"#fy#$($_.Name)#fe#"}
# Used percentage between 90% and 95% is orange
elseif($p -lt 95){"#fo#$($_.Name)#fe#"}
# Used percentage between 95% and 100% is red
else{"#fr#$($_.Name)#fe#"}}},
'Datacenter',
@{N='CapacityGB';E={[math]::Round($_.CapacityGB,1)}},
@{N='FreeSpaceGB';E={[math]::Round($_.FreeSpaceGB,1)}},
@{N='UsedPercent';E={$script:p}} |
ConvertTo-Html -Head $style
# Set the colors (red, yellow, green)
$body = $body.Replace('#fg#',"<font color=$fontGreen>").Replace('#fy#',"<font color=$fontYellow>").Replace('#fo#',"<font color=$fontOrange>").Replace('#fr#',"<font color=$fontRed>").Replace('#fe#','</font>')
# Set the email parameters
$sMail = @{
To =
From =
Subject =
BodyAsHtml = $true
Body = $body | Out-String
SmtpServer =
}
# Send the email
Send-MailMessage @smail
# Close connection
Disconnect-VIServer $connection -Confirm:$false
With Regards,
Mohamed Bilal