Subscribe
Accepted Solution

Powershell command to list snapshot details for particular volumes

Hi All,

 

I am looking for Powershell command to list snapshot details for particular volumes. I tried below command but getting o/p for last volume in list.

 

volumes.txt have identified volume list.

 

foreach ($volume in Get-Content volumes.txt) { Get-NcSnapshot $volume| select Volume,Name,Created|Export-Csv snapshot.csv }

Is there any way to list snapshot created only in particular time range ex (9AM to 1PM)?

 

Thanks in Advance,

Ram

Re: Powershell command to list snapshot details for particular volumes

Hi Ram,

 

The "Created" property is an alias to the AccessTimeDT property, which is a standard PowerShell DateTime object.  This means it has properties like "hour" which you can use in your selector.  Here is an example which will return all snapshots created between 9am and 1pm.

 

Get-NcVol | Get-NcSnapshot | Where-Object { $_.Created.hour -ge 9 -and $_.Created.hour -le 13 }

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Re: Powershell command to list snapshot details for particular volumes

Hi Andrew,

 

Thanks for your reply. This works for me.. 

 

Is there any way to get snapshot details for identified volumes instead of all volumes in a filer?

Can I get more specific output for example 8/15/2015 1 to 3 AM snapshots?

 

Ram

Re: Powershell command to list snapshot details for particular volumes

There is a number of different ways to do the selector...

 

 

# use an array iterator
@("vol1", "vol2", "vol3") | %{ Get-NcVol -Name $_ } | Get-NcSnapshot .......

# use the "in" operator
Get-NcVol | ?{ $_.Name -in @("vol1", "vol2", "vol3") } | Get-NcSnapshot ........

# using a text file, one volume name per line
Get-Content volumes.txt | %{ Get-NcVol -Name $_ } | Get-NcSnapshot .......

# use a wild card match
Get-NcVol | ?{ $_.Name -like "vol*" } | Get-NcSnapshot .......

# use a wild card exclude
Get-NcVol | ?{ $_.Name -notlike "root*" } | Get-NcSnapshot .........

 

As for more specific dates, the DateTime object has parameters for all of the date components...year, month, day, hour, minute, etc.  If you want to check for "today", for example, you could do this:

 

 

# Get snapshots created today
Get-NcSnapshot | ?{ $_.Created.ToShortDateString() -eq (Get-Date).ToShortDateString() }

 

You could also use relative time periods:

 

 

# Get snapshots less than 7 days old
Get-NcSnapshot | ?{ $_.Created -gt (Get-Date).AddDays(-7) }

# Get snapshots more than 7 days old
Get-NcSnapshot | ?{ $_.Created -lt (Get-Date).AddDays(-7) }

 

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.