Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
I am trying to create a powershell script that will give me every volume that has not created a snaphot is the last 2 hours.
get-ncvol | get-ncsnapshot | where-object {$_.createdhour -g 2}
this only give me snapshots creat at 2 am
Solved! See The Solution
Try this code:
$vols = Get-NcVol foreach ($vol in $vols) { Get-NcSnapshot | Where-Object { $_.Created -le (Get-Date).AddHours(-2) -and $_.Volume -eq $vol } | Sort-Object AccessTimeDT -Descending | Select-Object -First 1 ` @{l = "Volume"; e = { $_.Volume } }, @{l = "Snapshot"; e = { $_.Name } }, @{l = "CreatedTime"; e = {$_.Created}} }
I used some calculated properties to clean up the output a bit, but you can customize it too if there are additional properties you want to show beyond what I have there.
Hope that helps!
Donny
I am not an ps expert, but there is way to get to know the same.
Following simple CLI from clustershell, will return the list of volumes thta have snapshot created in less than 2 hours.
::> volume snapshot show -create-time >2h
Basically, if 'no-ouput' that means all the volumes here are candidate, if you do get 'some-output' that means except those rest all are the candidate.
Hopefully, some ps expert could provide you with ps commands you need.
I know this is not efficient but that's all I can think of now.
Try this code:
$vols = Get-NcVol foreach ($vol in $vols) { Get-NcSnapshot | Where-Object { $_.Created -le (Get-Date).AddHours(-2) -and $_.Volume -eq $vol } | Sort-Object AccessTimeDT -Descending | Select-Object -First 1 ` @{l = "Volume"; e = { $_.Volume } }, @{l = "Snapshot"; e = { $_.Name } }, @{l = "CreatedTime"; e = {$_.Created}} }
I used some calculated properties to clean up the output a bit, but you can customize it too if there are additional properties you want to show beyond what I have there.
Hope that helps!
Donny
Thanks!