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
The $session variable will be empty since you redirect the result of the New-SSHSession cmdlet to Out-Null
Replace that line with
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The $session variable will be empty since you redirect the result of the New-SSHSession cmdlet to Out-Null
Replace that line with
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you very much LucD.