Microsoft Virtualization Discussions

Get-Ncvol,Remove-Ncvol,Set-Ncvol from a file

SaravanaPandi
10,416 Views

Hi NetApp Admins, I am new to Netapp powershell and i has this confusion

 

volumes12.txt contains list of volumes 

foreach( $vol in Get-Content ".\volumes12.txt") {
 {

 

Get-NcVol $vol -Verbose

Set-Ncvol $vol 

 

}

 

None of the above commands seems to work,

 

whereas if i do this through an array it works.

 

$volumelist = get-ncvol -Name *sqlvol1* | Select-Object $_.Volume
ForEach ($vol in $volumelist)
{

Set-NcVol $vol -Offline -Verbose
}

 

at present i have lots of offline volumes in a text file, i want to to remove/destroy the volumes by reading that file

1 ACCEPTED SOLUTION

asulliva
8,543 Views

The first error you're getting is because the value of $filename is invalid.  The value of the $filename variable should be either a canonical or relative path + filename for the text file which contains the volume names.  For example, here's how I generated my test volume list:

 

# get 10 random, volumes which are not node or SVM root volumes
$volumes = Get-NcVserver $svmName | Get-NcVol -Attributes @{} -Query @{ VolumeStateAttributes = @{ IsNodeRoot = $false; IsVserverRoot = $false } } | Get-Random -Count 10 | Select-Object -ExpandProperty Name | Out-File ./volumes.txt $volumes | Out-File "C:\Users\asulliva\Documents\volumes.txt"

The result looks like this:

 

2018-04-12 09_35_19-Windows PowerShell ISE.png

 

From there, I simply execute the code from above:

 

Get-Content ./volumes.txt | %{
    Get-NcVol -Vserver $svmName -Name $_.Trim()
}

Resulting in...

 

2018-04-12 09_40_48-Windows PowerShell ISE.png

 

The second "error", or rather lack of correct output, is because you aren't using the trim function on the string being read from the file.

 

Andrew

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

View solution in original post

11 REPLIES 11
Public