Great suggestions, both added to my function. Thanks!
Note: I've changed the 'Used' value to '%FilesUsed' as there's now a Used attribute as standard on every volume (this function was written with Toolkit v1!).The final code is;
function Get-NaMaxfiles {
<#
.SYNOPSIS
Find volumes where the maxfiles values is greater than a specified threshold (default 50%).
.DESCRIPTION
Find volumes where the maxfiles values is greater than a specified threshold (default 50%).
.PARAMETER Controller
NetApp Controller to query (defaults to current controller if not specified).
.PARAMETER Percent
Filters the results to volumes when the %used files is greater than the number specified. Defaults to 50% if not specified.
.EXAMPLE
connect-NaController zcgprsan1n1 | get-NaMaxfiles -Percent 30
Get all volumes on filer zcgprsan1n1 where the number of files used is greater than 30% of the max available
#>
[cmdletBinding()]
Param(
[Parameter(Mandatory=$false,
ValueFromPipeLine=$true
)]
[NetApp.Ontapi.Filer.NaController]
$Controller=($CurrentNaController)
,
[Parameter(Mandatory=$false)]
[int]
$Percent=50
)
Begin {
#check that a controller has been specified
}
Process {
$exception = $null
try {
# create a null valued instance of $vol within the local scope
$vols = $null
$vols = Get-NaVol -controller $Controller -ErrorAction "Stop" | where {$_.FilesTotal -gt 0 -and ($_.FilesUsed/$_.FilesTotal)*100 -gt $Percent}
#check that at least one volume exists on this controller
if ($vols -ne $null) {
foreach ($vol in $vols) {
#calculate the percentage of files used and add a field to the Volume object with the value
$filesPercent = [int](($vol.FilesUsed/$vol.FilesTotal)*100)
add-member -inputobject $vol -membertype noteproperty -name Controller -value $Controller.Name
add-member -inputobject $vol -membertype noteproperty -name %FilesUsed -value $filesPercent
}
}
}
catch {
$exception = $_
}
if ($exception -eq $null) {
$returnValue = ($vols | Sort-Object -Property "Used" -Descending | Select-Object -Property "Controller","Name","FilesUsed","FilesTotal","%FilesUsed")
}
else {
$returnValue = $exception
}
return $returnValue
}
}