PowerCLI

 View Only
  • 1.  Help on running plink for multiple servers.

    Posted Mar 27, 2017 11:04 AM

    Sorry for posting here but I am sure the Master LucD will help me on this.

    Please correct me on this code.

    When I execute without using for loop for importing servers the command is executing successfully but while adding forloop its failing with below error.

    $CSVPath ='C:\IDRAC.csv'

    foreach($row in Import-Csv -Path $CSVPath){

    $User = 'root'

    $Pswd = 'Test@1234'

    $hst = $row.IDRAC

    $plink = "D:\plink.exe"  # Plink Path

    $plinkoptions = " -v -batch -pw $Pswd"

    $cmd = @'

    racadm config -g cfgUserAdmin -o cfgUserAdminPassword -i 2 Test@12345

    '@

    $remoteCommand = '"' + $cmd + '"'

    foreach ($hstpwdchange in $hst) {

    $command = $plink + " " + $plinkoptions + " " + $User + "@" + $hstpwdchange + " " + $remoteCommand

    $result = Invoke-Expression -command $command

    "" | select @{N="Executed On IDRAC";E={$hstpwdchange}},

        @{N="Result";E={$result}}

    }

    }

    #racadm set iDRAC.Users.2.Password "Test@1234"

    Error:



  • 2.  RE: Help on running plink for multiple servers.

    Posted Mar 27, 2017 11:17 AM

    You might want to try the 'echo Y' trick. Alan documented that in SSH PowerShell tricks with plink.exe.

    From the error it looks like the host key is not yet in your system



  • 3.  RE: Help on running plink for multiple servers.

    Posted Mar 27, 2017 11:57 AM

    No Luck:smileysad: Same Error

    Tried like this

    $command = "echo Y | " + $plink + " " + $plinkoptions + " " + $User + "@" + $hstpwdchange + " " + $remoteCommand

    $result = Invoke-Expression -command $command

    Connecting to 10.Xx.XX.XX port 22

    We claim version: SSH-2.0-PuTTY_Release_0.67

    Server version: SSH-2.0-OpenSSH_5.2

    We believe remote version has SSH-2 channel request bug

    Using SSH protocol version 2

    Doing Diffie-Hellman group exchange

    Doing Diffie-Hellman key exchange with hash SHA-256

    Host key fingerprint is:

    ssh-rsa 2048 65:cc:8c:90:44:97:b4:c4:e8:64:2c:b9:df:7d:82:d0

    The server's host key is not cached in the registry. You

    have no guarantee that the server is the computer you

    think it is.

    The server's rsa2 key fingerprint is:

    ssh-rsa 2048 65:cc:8c:90:44:97:b4:c4:e8:64:2c:b9:df:7d:82:d0

    Connection abandoned.

    Disconnected: Aborted at host key verification



  • 4.  RE: Help on running plink for multiple servers.

    Posted Mar 28, 2017 10:04 AM

    Some how I managed to work with this code., Only for few servers its showing error. But I can able to connect to that hosts using putty.

    Any thoughts  to fix this error.

    $CSVPath ='C:\IDRAC_187.csv'

    $User = 'root'

    $Pswd = 'test@123'

    $plink = "D:\plink.exe"  # Plink Path

    $plinkoptions = " -batch -pw $Pswd"

    $cmd = @'

    racadm config -g cfgUserAdmin -o cfgUserAdminPassword -i 2 test@1234

    '@

    $remoteCommand = '"' + $cmd + '"'

    foreach($hst in Import-Csv -Path $CSVPath){

    foreach ($hstpwdchange in $hst.IDRAC) {

    $command =  "echo Y | "+ " " + $plink + " " + $plinkoptions + " " + $User + "@" + $hstpwdchange + " " + $remoteCommand

    $result = Invoke-Expression -command $command

    "" | select @{N="Executed On IDRAC";E={$hstpwdchange}},

        @{N="Result";E={$result}}

    }

    }

    Success servers Output:

    Executed On IDRAC                  Result                           

    -----------------                                 ------                           

    server1-testdomain.com      Object value modified successfully

    server2-testdomain.com         Object value modified successfully

    Failure servers output:

    D:\plink.exe : The server's host key is not cached in the registry. You

    At line:1 char:11

    + echo Y |  D:\plink.exe  -batch -pw test@123 root@server3-testdomain. ...

    +           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (The server's ho...e registry. You:String) [], RemoteException

        + FullyQualifiedErrorId : NativeCommandError

    have no guarantee that the server is the computer you

    think it is.

    The server's rsa2 key fingerprint is:

    ssh-rsa 2048 a2:35:71:7c:b5:7c:3a:57:bb:02:ce:11:11:b9:42:a1

    Connection abandoned.



  • 5.  RE: Help on running plink for multiple servers.

    Posted Aug 25, 2021 12:28 PM

    Does anyone know how to use plink to connect to ESXi hosts with multiple passwords?
    Each ESXi host has it own password.



  • 6.  RE: Help on running plink for multiple servers.

    Posted Mar 27, 2017 01:36 PM

    Try this:

    $csv = Import-Csv -Path "C:\IDRAC.csv"

    $user = "root"

    $pass = "Test@1234"

    # ------------------------------------------

    $cmds = @(

        "racadm config -g cfgUserAdmin -o cfgUserAdminPassword -i 2 Test@12345"

    )

    # ------------------------------------------

    $csv | foreach {

    $address = $_.IDRAC

    # ------------------------------------------

        $plink_exe = "D:\plink.exe"

        $plink_option = "-ssh $address -l $user -pw $pass"

        $plink_cmd = ""

           $cmds | foreach {

               $plink_cmd += $_ + "`n"

            }

    # ------------------------------------------

        $plink_run = "echo n | " + $plink_exe + " " + $plink_option + " " + """$plink_cmd"""

        $result = Invoke-Expression $plink_run

    }



  • 7.  RE: Help on running plink for multiple servers.

    Posted Mar 28, 2017 09:52 AM

    Hi

    Its not working:

    ERROR: The specified object value is not valid.

    ERROR: The specified object value is not valid.