The cmdlets to use will be Get-NaVol and Get-NaSnapshot.
Get-NaVol returns an array of objects of type VolumeInfo. VolumeInfo objects include a property named "CloneParent". This property returns an array of objects of type CloneParentInfo. I'm not sure whether it is possible for a volume clone to have more than parent, I'm not sure why this property returns an array. Perhaps clones of clones will return a different result. You may want to do some proof-of-concept testing on this point. The CloneParentInfo object includes properties named "ParentSnapshotName" and "ParentVolumeName".
Get-NaSnapshot returns an array of SnapshotInfo objects for a given volume. Depending on how busy the NetApp controller is, it is very possible for this cmdlet to timeout. I, therefore, recommend that you do some error handling around this step. Error handling is not shown in this code. Each SnapshotInfo object contains properties including "Created", "Dependency", and "Name". For easy of coding, I have assumed that only snapshots with no dependencies are usable. (I did this to avoid grabbing temporary snapshots which are created for SnapMirror, SnapVault, A-SIS, etc.).
Here is the code:
$netapp = $hilav1file5
#Get a list of volumes and sort by name
$vols = Get-NaVol -Controller $netapp | Sort-Object -Property "Name"
#Filter for volumes whose names begin with "clone_"
$cloneVols = $vols | Where-Object {$_.Name -match "^clone_"}
foreach ($vol in $CloneVols) {
if ($vol.CloneParent -ne $null) {
foreach ($parent in $cloneParent) {
#Instantiate $snaps and $parentVol as $null to eliminate stale values from the last iteration
$snaps = $null
$parentVol = $null
$parentVolName = $parent.ParentVolumeName
$parentSnapName = $parent.ParentSnapshotName
$parentVol = Get-NaVol -Controller $netapp | Where-Object {$_.name -eq $parentVolName}
if ($parentVol -ne $null) {
$snaps = Get-NaSnapshot -Controller $netapp -TargetName $parentVol.Name | Sort-Object -Property "Created" -Descending
if ($snaps -ne $null) {
#Snapshots used by other processes like SnapMirror, SnapVault, A-SIS, etc. should be excluded.
$usableSnaps = $snaps | Where-Object {$_.Dependency -eq ""}
if ($usableSnaps -ne $null) {
$parentSnap = $snaps | Where-Object {$_.Name -eq $parentSnapName}
if ($parentSnap.Created -lt $usableSnaps[0].Created) {
write-host "Newer snapshot exists for $($vol.name). The snapshot is named $($usableSnaps[0].name)"
}
}
}
}
}
}
}