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.