Microsoft Virtualization Discussions

Powershell Pipe issues

Beardmann
1,219 Views

Hi there

 

This might be a PS issue more than a NetApp issue, yet I will give it a try here 🙂

 

I'm trying to do a list of snapshots on volumes that are older than a specific date...

I connect OK to the cluster, and I can go a get-ncvol with no issues.. but when I try to add pipes to it, so to get the snapshots, it complains... 

 

so this works OK:

$volumes = get-ncvol

 

But this fails:

$snapshots = get-ncvol | get-ncsnapshot

 

And this also fails:

$oldsnapshots = get-ncvol | get-ncsnapshot | where-object {$_.created -lt "$maxsnapshotdesiredage"}

 

Finding old snapshots...
get-ncsnapshot : Volume parameter neither specified nor set
At C:\Users\blah\Documents\list.ps1:15 char:17
+ $oldsnapshots | get-ncsnapshot | where-object {$_.created -lt "$maxsn ...
+                 ~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-NcSnapshot], ArgumentException
+ FullyQualifiedErrorId : Volume is empty,DataONTAP.C.PowerShell.SDK.Cmdlets.Snapshot.GetNcSnapshot

So it looks like when ever I use a |Pipe| it complains... 

 

PS C:\Users\blah\Documents> $PSVersionTable.PSVersion

Major Minor Build Revision
----- ----- ----- --------
5 1 14409 1029

 

This has been working from this Windows hosts before... so my guess it that it is some Powershell thing that has changed as it has most likely been upgraded since I last used it....

 

Any help is welcome...

 

2 REPLIES 2

clariion
1,066 Views

Hi,

I had exactly the same issue. I have solved it by bypassing the pipes in the command.

 

$Volumes = Get-NcVol
$Snapshots = foreach ($Volume in $Volumes) {
$VolumeSnapshots = Get-NcSnapshot -Volume $Volume | Where-Object  {$_.created -lt "$maxsnapshotdesiredage"}
$VolumeSnapshots
}

RobDBA
1,038 Views

Trying to pipe Get-NcVol to Get-NcSnapshot directly shouldn't work since they don't use the same parameter for specifying the volume name.  Use this method to rename the parameter on a pipe:

 

Get-NcVol | % { Get-NcSnapshot -Volume $_.Name }

 

 

Public