Highlighted
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

0 Kudos
5 Replies
Highlighted
Expert
Expert

this was working on plink 0.67

but after upgrading to 0.74 its broken

0 Kudos
Highlighted
User Moderator
User Moderator

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

0 Kudos
Highlighted
Expert
Expert

let me check it out.

Thanks Luc

0 Kudos
Highlighted
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

0 Kudos
Highlighted
User Moderator
User Moderator

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

0 Kudos