Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Powershell - Get a list of volumes that have not created a snapshot in the last # of hours
2019-09-24
06:24 AM
5,374 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
1 ACCEPTED SOLUTION
Tmbridges has accepted the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Tmbridges has accepted the solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks!
