VMware Cloud Community
mahady_hassan
Enthusiast
Enthusiast
Jump to solution

Datastore Usage 80% or above

Hi, I am using the below script for datastore usage in the environment

Script:

# Get the list of vCenter datastores
$frag6 = Get-Datastore |
Select-Object Name, Type, Datacenter,
@{N='CapacityGb';E={[math]::Round($_.CapacityGB,3)}},
@{N = 'FreeSpaceGb'; E = { [Math]::Round(($_.ExtensionData.Summary.FreeSpace) / 1GB, 3)} },
@{N = 'PercentsFree'; E = {"{0:P0}" -f [math]::Round(($_.FreeSpaceGB) / ($_.CapacityGB), 2)}},
@{N = 'ProvisionedSpaceGb'; E = { [Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / 1GB, 3)} },
@{N = 'PercentsOvercommit'; E = { "{0:P0}" -f [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / ($_.CapacityGB*1GB), 2) } } |
Sort-Object -Property PercentsFree |
ConvertTo-Html -Fragment -As table -PreContent "<h2>Datastore Usage Percentage</h2>" -PostContent '<i>' |
Out-String 

 

Now I want to see only those datastore which usage is more than 80% not all the datastore in the environment. can anyone help to incorporate the script with necessary changes

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You should be able to do that by adding a WHere-Object 

$frag6 = Get-Datastore |
    Select-Object Name, Type, Datacenter,
    @{N = 'CapacityGb'; E = { [math]::Round($_.CapacityGB, 3) } },
    @{N = 'FreeSpaceGb'; E = { [Math]::Round(($_.ExtensionData.Summary.FreeSpace) / 1GB, 3) } },
    @{N = 'PercentsFree'; E = { "{0:P0}" -f [math]::Round(($_.FreeSpaceGB) / ($_.CapacityGB), 2) } },
    @{N = 'ProvisionedSpaceGb'; E = { [Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / 1GB, 3) } },
    @{N = 'PercentsOvercommit'; E = { "{0:P0}" -f [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / ($_.CapacityGB * 1GB), 2) } } |
    Where-Object {$_.PercentsFree -le 20} |
    Sort-Object -Property PercentsFree |
    ConvertTo-Html -Fragment -As table -PreContent "<h2>Datastore Usage Percentage</h2>" -PostContent '<i>' |
    Out-String 


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

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

You should be able to do that by adding a WHere-Object 

$frag6 = Get-Datastore |
    Select-Object Name, Type, Datacenter,
    @{N = 'CapacityGb'; E = { [math]::Round($_.CapacityGB, 3) } },
    @{N = 'FreeSpaceGb'; E = { [Math]::Round(($_.ExtensionData.Summary.FreeSpace) / 1GB, 3) } },
    @{N = 'PercentsFree'; E = { "{0:P0}" -f [math]::Round(($_.FreeSpaceGB) / ($_.CapacityGB), 2) } },
    @{N = 'ProvisionedSpaceGb'; E = { [Math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / 1GB, 3) } },
    @{N = 'PercentsOvercommit'; E = { "{0:P0}" -f [math]::Round(($_.ExtensionData.Summary.Capacity - $_.ExtensionData.Summary.FreeSpace + $_.ExtensionData.Summary.Uncommitted) / ($_.CapacityGB * 1GB), 2) } } |
    Where-Object {$_.PercentsFree -le 20} |
    Sort-Object -Property PercentsFree |
    ConvertTo-Html -Fragment -As table -PreContent "<h2>Datastore Usage Percentage</h2>" -PostContent '<i>' |
    Out-String 


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

mahady_hassan
Enthusiast
Enthusiast
Jump to solution

Thanks Luc. Its working fine

Reply
0 Kudos