Automation

 View Only
  • 1.  plink issues

    Posted Oct 21, 2020 08:38 PM

    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



  • 2.  RE: plink issues

    Posted Oct 21, 2020 08:48 PM

    this was working on plink 0.67

    but after upgrading to 0.74 its broken



  • 3.  RE: plink issues

    Posted Oct 21, 2020 08:53 PM

    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



  • 4.  RE: plink issues

    Posted Oct 22, 2020 05:20 AM

    let me check it out.

    Thanks Luc



  • 5.  RE: plink issues

    Posted Oct 22, 2020 01:03 PM

    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



  • 6.  RE: plink issues

    Posted Oct 22, 2020 01:18 PM

    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.