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
this was working on plink 0.67
but after upgrading to 0.74 its broken
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
let me check it out.
Thanks Luc
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
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