Try something like this:
function Remove-Snapshots()
{
[CmdletBinding(SupportsShouldProcess=$true)]
param
(
[Parameter(Mandatory=$true,Valuefrompipeline=$true)] $Volume,
[string] $SnapName = "*",
[int] $DaysOld = 5
)
begin
{}
process
{
foreach ( $vol in $Volume )
{
$volObj = $vol
if ( $vol -is [string] )
{
# If user provided a volume name as a string
$volObl = Get-NaVol -Name $vol
}
$vol | Get-NaSnapshot | Where-Object -FilterScript { $_.Name -ilike $SnapName -and $_.Name -inotmatch "\.\d+?$" -and (New-TimeSpan -Start $_.AccesstimeDt).totalDays -gt $DaysOld } | Remove-NaSnapshot
}
}
}
Import-Module dataontap
Connect-NaController controller1 -rpc
Get-NaVol | Remove-Snapshots
"vol1" | Remove-Snapshots