Microsoft Virtualization Discussions

Get-NaAggrSpace from multiple filers are failing

NAMAN
2,793 Views

 

 

foreach ($filer in Get-Content H:\7mode.txt)

 

{ $c = Connect-NaController | Get-NaAggrSpace | select AggregateName,@{l='SizeFree(GB)';e={([math]::Round([decimal]($_.SizeFree)/1gb,2))}},@{l='SizeSnapUsed(GB)';e={([math]::Round([decimal]($_.SizeSnapUsed)/1gb,2))}}} | export-csv H:\aggr.csv

 

I'm new to powershell and noob in scripting.  Can somebody please help to get aggr size from multi filers and export it to a file in csv format?

 

thank you

 

 

3 REPLIES 3

Aparajita
2,764 Views

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

NAMAN
2,748 Views

Thank you soooo much for your prompt reply and solution.  I ran the script as below but I'm seeing only one aggr in the csv file although I have more than 10 filers.  When I run I don't see any errors either.  

 

I removed this line as I can run the script without it.

$c = Connect-NaController $filer #-HTTPS -Credential $script_credential, in case RPC can not be used

 

 

foreach ($filer in Get-Content H:\7mode.txt)
{

$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 Controller –Value $global:CurrentNaController

$output | Export-CSV H:\aggr.csv -Append
}
}

Aparajita
2,736 Views

Hi Naman,

 

The reason you are getting output from only one controller is because you removed the `Connect-NcController $filer`from inside the loop. The Get-AggrSpace ends up being run against the same filer (which you are already connected to, before running the loop) 'n' times - n being the number of filers in 7mode.txt

 

 

Public