View Only
  • 1.  issue validating ssh login

    Posted Dec 17, 2019 11:40 AM


    I am not able to get the validate of ssh login from below script.

    If the password is wrong, I get False and it gets captured in the output.

    If the password is correct, Password_Validation field and Version field shows blank and not getting captured in the output

    Please help



    get-vm | where{$_.ExtensionData.Config.GuestFullname -match "Cent"} | select @{n='Server';e={$_.Name}} | sort Server | export-csv .\hostpassvalidation.csv -NoTypeInformation

    disconnect-viserver -server * -force -confirm:$false

    $Username = 'root'

    $pass = ConvertTo-SecureString -AsPlainText 'password' -Force

    $Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass

    Import-Csv -Path .\hostpassvalidation1.csv -UseCulture -PipelineVariable row |

    ForEach-Object -Process {



       $session = New-SSHSession $row.Server -Credential $Cred -AcceptKey -ErrorAction Stop | Out-Null

       $result = $session | Select-Object -ExpandProperty Connected

       $output = $((Invoke-SSHCommand -SSHSession $session -Command 'adinfo -v').output)

      Get-SSHSession | Remove-SSHSession | Out-Null




       $result = 'False'


       $row | Add-Member -MemberType NoteProperty -Name 'Password_Validation' -Value $result -PassThru | Add-Member -MemberType NoteProperty -Name 'Version' -Value $output -PassThru

    } | ft -auto


    Server      Password_Validation Version

    ------      ------------------- -------

  • 2.  RE: issue validating ssh login
    Best Answer

    Posted Dec 17, 2019 01:22 PM

    The $session variable will be empty since you redirect the result of the New-SSHSession cmdlet to Out-Null

    Replace that line with

    $session = New-SSHSession $row.Server -Credential $Cred -AcceptKey -ErrorAction Stop

  • 3.  RE: issue validating ssh login

    Posted Dec 18, 2019 04:39 AM

    Thank you very much LucD. :smileyhappy: