NetApp Community Update
This site will enter Read Only mode on July 23 as we prepare to move to a new platform. You will still be able to view content, but posting and replying will be temporarily disabled.
We're excited to launch our new Community experience on July 30 and more information will follow soon.
Stay connected during the transition - Join our Discord community today.

Microsoft Virtualization Discussions

Powershell - Get a list of volumes that have not created a snapshot in the last # of hours

Tmbridges
6,912 Views

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 

1 ACCEPTED SOLUTION

donny_lang
6,834 Views

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

 

View solution in original post

3 REPLIES 3

Ontapforrum
6,891 Views

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.

donny_lang
6,835 Views

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

 

Tmbridges
6,712 Views

Thanks!

Public