esxi1979
Expert
Expert

DS audit

Jump to solution

$ds = Get-Datastore |where {$_.type -eq "NFS"} | Get-View

$ds | Select -ExpandProperty Summary | select name, @{N="Capacity (GB)"; E={[math]::round($_.Capacity/1GB,2)}}, @{N="FreeSpace (GB)"; E={[math]::round($_.FreeSpace/1GB,2)}}, @{N="Provisioned (GB)"; E={[math]::round(($_.Capacity - $_.FreeSpace + $_.Uncommitted)/1GB,2) }}| sort -Property Name

This works well

I need to modify this with below :-

1. Get only DS where free space is above X%

2. Get DS where OverCommit (prov ) % is above twice or 1.5 ( or better Y)

3. Get DS where actual free space is only W GB or less

Sort the output for #3.

Get the data all 3 above

Thanks

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try something like this

$freeWatermarkPercent = 25

$freeWatermarkGB = 300

$overcommit = 1.5

Get-view -ViewType Datastore -Property Name,Summary -Filter @{'Summary.Type'='NFS'} |

where{($_.Summary.FreeSpace/$_.Summary.Capacity)*100 -ge $freeWatermarkPercent -and

      ($_.Summary.Capacity - $_.Summary.FreeSpace + $_.Summary.Uncommitted)/$_.Summary.Capacity -gt $overcommit -and

      ($_.Summary.FreeSpace/1GB) -le $freeWatermarkGB} |

Select-Object name,

        @{N="Capacity (GB)"; E={[math]::round($_.Summary.Capacity/1GB,2)}},

        @{N="FreeSpace (GB)"; E={[math]::round($_.Summary.FreeSpace/1GB,2)}},

        @{N="Provisioned (GB)"; E={[math]::round(($_.Summary.Capacity - $_.Summary.FreeSpace + $_.Summary.Uncommitted)/1GB,2) }}


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership

Try something like this

$freeWatermarkPercent = 25

$freeWatermarkGB = 300

$overcommit = 1.5

Get-view -ViewType Datastore -Property Name,Summary -Filter @{'Summary.Type'='NFS'} |

where{($_.Summary.FreeSpace/$_.Summary.Capacity)*100 -ge $freeWatermarkPercent -and

      ($_.Summary.Capacity - $_.Summary.FreeSpace + $_.Summary.Uncommitted)/$_.Summary.Capacity -gt $overcommit -and

      ($_.Summary.FreeSpace/1GB) -le $freeWatermarkGB} |

Select-Object name,

        @{N="Capacity (GB)"; E={[math]::round($_.Summary.Capacity/1GB,2)}},

        @{N="FreeSpace (GB)"; E={[math]::round($_.Summary.FreeSpace/1GB,2)}},

        @{N="Provisioned (GB)"; E={[math]::round(($_.Summary.Capacity - $_.Summary.FreeSpace + $_.Summary.Uncommitted)/1GB,2) }}


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

View solution in original post

0 Kudos
esxi1979
Expert
Expert

I modified it

# Get only DS where free space is below X%

$freeWatermarkPercent = 5

# Get DS where actual free space is only 100 GB or less

$freeWatermarkGB = 100

# Get DS where OverCommit (prov ) % is above twice

$overcommit = 1.5

Get-view -ViewType Datastore -Property Name,Summary -Filter @{'Summary.Type'='NFS'} |

where{($_.Summary.FreeSpace/$_.Summary.Capacity)*100 -lt $freeWatermarkPercent -or

      ($_.Summary.Capacity - $_.Summary.FreeSpace + $_.Summary.Uncommitted)/$_.Summary.Capacity -gt $overcommit -or

      ($_.Summary.FreeSpace/1GB) -le $freeWatermarkGB} |

Select-Object name,

        @{N="Capacity (GB)"; E={[math]::round($_.Summary.Capacity/1GB,2)}},

        @{N="FreeSpace (GB)"; E={[math]::round($_.Summary.FreeSpace/1GB,2)}},

        @{N="Provisioned (GB)"; E={[math]::round(($_.Summary.Capacity - $_.Summary.FreeSpace + $_.Summary.Uncommitted)/1GB,2) }}

And made it or & then the o/p does not suggest which of the 3 case it hit... how this problem is fixed ?

0 Kudos
LucD
Leadership
Leadership

You could do something like this

# Get only DS where free space is below X%

$freeWatermarkPercent = 5

# Get DS where actual free space is only 100 GB or less

$freeWatermarkGB = 100

# Get DS where OverCommit (prov ) % is above twice

$overcommit = 1.5

Get-view -ViewType Datastore -Property Name,Summary -Filter @{'Summary.Type'='NFS'} | %{

    $freePCTVal = ($_.Summary.FreeSpace/$_.Summary.Capacity)*100

    $freeGBVal = ($_.Summary.FreeSpace/1GB)

    $overVal = ($_.Summary.Capacity - $_.Summary.FreeSpace + $_.Summary.Uncommitted)/$_.Summary.Capacity

    $freePCT = $freeGB = $over = $false

    if($freePCTVal * 100 -lt $freeWatermarkPercent){

        $freePCT = $true

    }

    if($freeGBVal -le $freeWatermarkGB){

        $freeGB = $true

    }

    if($overVal  -gt $overcommit){

        $over = $true

    }

    if($freePCT -or $freeGB -or $over){

        $_ | Select-Object name,

            @{N='Free % warning';E={$freePCT}},

            @{N='Free GB warning';E={$freeGB}},

            @{N='Overcommit warning';E={$over}},

            @{N="Capacity (GB)"; E={[math]::round($_.Summary.Capacity/1GB,2)}},

            @{N="FreeSpace (GB)"; E={[math]::round($_.Summary.FreeSpace/1GB,2)}},

            @{N="Provisioned (GB)"; E={[math]::round(($_.Summary.Capacity - $_.Summary.FreeSpace + $_.Summary.Uncommitted)/1GB,2) }}

    }

}


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