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:
From there, I simply execute the code from above:
Get-Content ./volumes.txt | %{
Get-NcVol -Vserver $svmName -Name $_.Trim()
}
Resulting in...
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.