VMware Cloud Community
vin01
Expert
Expert

Help on running plink for multiple servers.

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:

plinkerror.JPG

Regards Vineeth.K
Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
vin01
Expert
Expert

No LuckSmiley Sad 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

Regards Vineeth.K
Reply
0 Kudos
rwk1982
Enthusiast
Enthusiast

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

}

Drink coffee.. Do stupid things faster with more energy...
Reply
0 Kudos
vin01
Expert
Expert

Hi

Its not working:

ERROR: The specified object value is not valid.

ERROR: The specified object value is not valid.

Regards Vineeth.K
Reply
0 Kudos
vin01
Expert
Expert

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.

Regards Vineeth.K
Reply
0 Kudos
LukaszMadajczyk
Contributor
Contributor

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

Reply
0 Kudos