Microsoft Virtualization Discussions

foreach from file not working

JSHACHER11
5,242 Views

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; (:) [Connect-NaController], Paramet

   erBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl

   lowed,DataONTAP.PowerShell.SDK.ConnectNaController

what am I doing wrong?

Cheers

1 ACCEPTED SOLUTION

vinith
5,238 Views

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

View solution in original post

10 REPLIES 10
Public