beardmann

Snapdrove powershell

Apr 21st, 2015
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Remove-Snapshots()
  2. {
  3.   [CmdletBinding(SupportsShouldProcess=$true)]
  4.   param
  5.   (
  6.     [Parameter(Mandatory=$true,Valuefrompipeline=$true)] $Volume,
  7.     [string] $SnapName = "*",
  8.     [int] $DaysOld = 5
  9.   )
  10.   begin
  11.   {}
  12.  
  13.   process
  14.   {
  15.     foreach ( $vol in $Volume )
  16.     {
  17.       $volObj = $vol
  18.      
  19.       if ( $vol -is [string] )
  20.       {
  21.         #  If user provided a volume name as a string
  22.         $volObl = Get-NaVol -Name $vol
  23.       }
  24.      
  25.       $vol | Get-NaSnapshot | Where-Object -FilterScript { $_.Name -ilike $SnapName -and $_.Name -inotmatch "\.\d+?$" -and (New-TimeSpan -Start $_.AccesstimeDt).totalDays -gt $DaysOld } | Remove-NaSnapshot
  26.     }
  27.   }  
  28. }
  29. Import-Module dataontap
  30. Connect-NaController controller1 -rpc
  31. Get-NaVol | Remove-Snapshots
  32. "vol1" | Remove-Snapshots
Advertisement
Add Comment
Please, Sign In to add comment