Connecting multiple servers with different password.

Hello Team

I am trying to connect multiple UCS servers using UCS powertool. Some servers has different password.How to connecting them in a loop and the script should try both the password’s, which I mentioned in the credential file. Please find below the sample code.

$ucsservers = get-content c:\scripts\servers.txt

$user = “admin”
$password = “password” | ConvertTo-SecureString -AsPlainText -Force
$password1 = “password1234” | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($user, $password)
$cred1 = New-Object System.Management.Automation.PSCredential($user, $password1)

foreach($ucs in $ucservers){
If (Connect-ucs -Name $ucs -nodefault -crediantial $cred)



Please advise which loop I need to use and how to do catch the connected or disconnected(password wrong) errors…


#Requires -Version 5
Install-Module POSH-SSH,SB-Tools -Force
Import-Module POSH-SSH,SB-Tools -DisableNameChecking

$ucsservers = Get-Content c:\scripts\servers.txt
$CredList = 1..2 | foreach { Get-SBCredential 'admin' }

$myOutput = foreach($ucs in $ucservers){
    Remove-Variable ValidCred -EA 0 
    0..1 | foreach {
        If (Connect-ucs -Name $ucs -nodefault -crediantial $CredList[$PSItem] -EA 0) {
            $ValidCred = $CredList[$PSItem]
        ComputerName = $ucs
        UserName     = $ValidCred.UserName
        Password     = $ValidCred.GetNetworkCredential().Password

$myOutput | FT -a