The $result variable is an array, hence the System.String[] in the output.
You must loop through all the lines in $result and output line by line.
To explain the FALSE indication you need to find out why the try-block was entered.
What does $error[0] say?
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
------------------------------
Original Message:
Sent: Jan 16, 2025 05:50 AM
From: ganapa2000
Subject: Password Validation Info shows wrong for Linux VMs
Hi,
I am trying to Disk info from Linux VMs, here even though Password validation is success, but the output file shows FALSE and also DiskInfo output shows as System.String[] in the output file
Please help!!
$command = @'
df -Th | grep '^/dev/' | grep -v '^/dev/sda' | grep -v '/dev/mapper/rhel-root' | tr -s ' ' | awk '{print $1 " > " $2 " > " $7}' | awk 'BEGIN {ORS="";} {print $0 " ; "} END {print "\n"}'
'@
Import-Csv -Path $reportlocation -UseCulture -PipelineVariable row |
ForEach-Object -Process {
try {
$myip = $($row.IP_Address)
#Write-Host "$myip"
$session = New-SSHSession $myip -Credential $Cred -AcceptKey -ErrorAction Stop
$connected = $session.Connected
Write-Host "Gathering Infomation on :: $($row.IP_Address)"
$result = (Invoke-SSHCommand -SSHSession $session -Command $command).Output
#Remove-SSHSession $session -Verbose | Out-Null
Stop-Transcript
Remove-SSHSession $session -Verbose 4>&1 | Out-Null
} catch {
$connected = 'FALSE'
$output = ''
}
$row | Add-Member -MemberType NoteProperty -Name 'Password_Validation' -Value $connected -PassThru | Add-Member -MemberType NoteProperty -Name 'DiskInfo' -Value $result -PassThru
} | Export-Excel -Path $reportlocation1 -AutoFilter -AutoSize -BoldTopRow -FreezeTopRow -WorksheetName Summary