Connecting multiple servers with different password.

Welcome Forums General PowerShell Q&A Connecting multiple servers with different password.

This topic contains 1 reply, has 2 voices, and was last updated by

9 months, 3 weeks ago.

  • Author
  • #100230

    Points: 0
    Rank: Member

    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..


  • #100233

    Points: 176
    Helping Hand
    Rank: Participant
    #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 

The topic ‘Connecting multiple servers with different password.’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort