Subscribe
Accepted Solution

foreach from file not working

I created a script to show aggregates more than 90% full on multiple filers but they would not connect

the text file is like this:

"filer1", "filer2", "filer3"

+++++++++++++++++++++++++++++++++++++++++++++++++++

$ntapArrays = (get-content "C:\filers.txt")

$FasUser = "root"

$FasPasswd = Read-Host "Enter password"

$SecureFasPasswd = ConvertTo-SecureString $FasPasswd -AsPlainText -Force

$FasCred = New-Object -TypeName System.Management.Automation.PSCredential ($FasUser, $SecureFasPasswd)

Foreach ($array in $ntapArrays) {

connect-nacontroller -Name $array -Credential $FasCred

Get-Naaggr | select homename, SizePercentageUsed, name | ? {$_.SizePercentageUsed -gt 90} | ft -AutoSize

}

++++++++++++++++++++++++++++++++++++++++++++++

the error messages is

Connect-NaController : Cannot bind argument to parameter 'Name' because it is a

n empty string.

At C:\script2.ps1:30 char:27

+ connect-nacontroller -Name <<<<  $array -Credential $FasCred

    + CategoryInfo          : InvalidData&colon; (Smiley Happy [Connect-NaController], Paramet

   erBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl

   lowed,DataONTAP.PowerShell.SDK.ConnectNaController

what am I doing wrong?

Cheers

Re: foreach from file not working

The way you are saving filer names in filers.txt is wrong, you need to append them as below

Re: foreach from file not working

OK, the Controllers are connecting now but I still don't get the aggregates info. Something is wrong here:

Foreach ($array in $ntapArrays) {

connect-nacontroller -Name $array -Credential $FasCred

Get-Naaggr | select homename, SizePercentageUsed, name | ? {$_.SizePercentageUsed -gt 90} | ft -AutoSize

}

Re: foreach from file not working

Hi Joel,

Instead of "filer1", "filer2", "filer3" save your txt as filer1,filer2,filer3

You can do it this way :

$ntapArrays = (get-content "C:\filers.txt")

$ntapArrays = $filertxt.Split(',')

Foreach ($array in $ntapArrays) {

...

Re: foreach from file not working

OK, the Controllers are connecting now but I still don't get the aggregates info. Something is wrong here:

Foreach ($array in $ntapArrays) {

connect-nacontroller -Name $array -Credential $FasCred

Get-Naaggr | select homename, SizePercentageUsed, name | ? {$_.SizePercentageUsed -gt 90} | ft -AutoSize

}

Re: foreach from file not working

The easiest thing to do here is to list them in a text file as stated above

filer1

filer2

filer3

Then just do

$filers = gc c:\filers.txt

That will create the array

Then just put that array into a loop

$filers | % {

$c = connect-nacontroller $_

Put code here

}

Also, you are doing something wrong in my opinion.  You need to put your where clause before your select statement. 

Get-Naaggr |  ? {$_.SizePercentageUsed -gt 90}| select homename, SizePercentageUsed, name |  | ft -AutoSize

Re: foreach from file not working

What is the output of

Get-NaAggr | select homename,SizePercentageUsed,name | ft -AutoSize

Can you confirm that you do have aggregates whose SizePercentageUsed is greater than 90?SizePercentageUsed is greater than 90?

Re: foreach from file not working

Vinith, you were right. That list didn't have aggregate with more than 90%

Thank you

Re: foreach from file not working

Thank you all - I will apply the advices

Re: foreach from file not working

Thank You For letting us know that