Hi Naman,
I see two problems with the PowerShell pipeline you created.
- Connect-NaController has be to passed $filer as argument - unlike Perl PowerShell has no $_ that is automatically utilized. So Connect-NaController in your case did not know what controller to connect to. Since no connection was made, 'Get-NaAggrSpace' was failing with 'Object in $global:currentNaController' is not of correct type'.
- Export-CSV has to be a part of the pipeline inside the for-loop. Putting Export-CSV outside the for means you're attempting to store the output of the foreach cmdlet (which is NULL. What you see on screen is output of the cmdlets inside foreach and are no longer part of the pipeline).
Fixing these two, adding a controller name to the output for ease of analysis and configuring RPC access on my 7-mode filers (if RPC does not work, you'll have to use HTTP/HTTPS & pass a Credential object to Connect-NaController), the script should look like this -
foreach ($filer in Get-Content H:\7mode.txt)
{
$c = Connect-NaController $filer #-HTTPS -Credential $script_credential, in case RPC can not be used
$rows = Get-NaAggrSpace | select AggregateName, @{l='SizeFree(GB)';e={([math]::Round([decimal]($_.SizeFree)/1gb,2))}}, @{l='SizeSnapUsed(GB)';e={([math]::Round([decimal]($_.SizeSnapUsed)/1gb,2))}}
foreach ($row in $rows) {
if ($row -ne $null) {
#Creating an object so that Export-CSV can give a pretty output
$output = New-Object –TypeName PSObject
$output | Add-Member –MemberType NoteProperty –Name AggregateName –Value $row.AggregateName
$output | Add-Member –MemberType NoteProperty –Name SizeFree –Value $row.'SizeFree(GB)'
$output | Add-Member –MemberType NoteProperty –Name SizeSnapUsed –Value $row.'SizeSnapUsed(GB)'
$output | Add-Member –MemberType NoteProperty –Name Controller –Value $global:CurrentNaController
$output | Export-CSV H:\aggr.csv -Append
}
}
The output CSV was
#TYPE System.Management.Automation.PSCustomObject
"AggregateName","SizeFree","SizeSnapUsed","Controller"
"aggr0","0.15","0.03","10.63.4.208"
"aggr1","0.14","0.00","10.63.4.208"
"aggr2","0.16","0.00","10.63.4.208"
"aggr3","132.15","1.38","10.72.211.52"
"aggr0","7.28","1.08","10.72.211.52"
Hope this helps!
Aparajita