VMware Cloud Community
tdubb123
Expert
Expert

plink issues

any idea why this is not working

$esxhosts = get-vmhost -name (get-content esxhosts.txt)

#$root_pass = read-host -Prompt "Enter root PAssword"

$root_pass = Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File encryptedpassword.txt

$encrypted = ConvertTo-SecureString(Get-Content ".\encryptedpassword.txt")

$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($encrypted)

$password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)

$cmd1 = '/etc/init.d/slpd stop'

foreach ($vmhost in $esxhosts) {

echo y | plink.exe $vmhost -pw $password -l root $cmd1 -batch

}

I keep getting this kind of prompt

Screen Shot 2020-10-21 at 1.39.04 PM.png

Reply
0 Kudos
5 Replies
tdubb123
Expert
Expert

this was working on plink 0.67

but after upgrading to 0.74 its broken

Reply
0 Kudos
LucD
Leadership
Leadership

I haven't tested that version yet.

But a quick question, why are you still using plink.exe?

With the Posh-SSH this has become a lot easier.

See for example Use Posh-SSH instead of PuTTY


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

Reply
0 Kudos
tdubb123
Expert
Expert

let me check it out.

Thanks Luc

Reply
0 Kudos
tdubb123
Expert
Expert

Hi luc,

Is there way to store the encrypted root creds in the script without prompting for get-credential?

$esxhosts = get-vmhost -name (get-content $HOME\scripts\esxhosts.txt)

$rootcreds = get-credential

$cmdSub = "/etc/init.d/slpd stop"

foreach ($vmhost in $esxhosts){

$session = New-SSHSession -ComputerName $vmhost.name -Credential $rootcreds -AcceptKey

$result = invoke-sshcommand -SSHSession $session -Command $cmdSub

Reply
0 Kudos
LucD
Leadership
Leadership

A .ps1 script is just a text file, so you can't store complex objects in there.

An alternative might be to export the credentials to an XML file with Export-CliXml.

And then in your script retrieve them with Import-CliXml.


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

Reply
0 Kudos