2 Replies Latest reply on Dec 17, 2019 8:39 PM by ganapa2000

    issue validating ssh login

    ganapa2000 Hot Shot

      Hi,

       

      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

       

      Script

      connect-viserver 10.10.10.10

      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 {

         try

         {

         $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

         }

         catch

         {

         $result = 'False'

         }

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

      } | ft -auto

       

       

      Output

      Server      Password_Validation Version

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

      172.27.4.71