Hi all
I know this is basic script, but I cannot export the values into a txt file.
It's just showing on the screen. I want to display the result onto the screen and export it to txt file after.
Sample output on all hosts:
Hostname:
Chassis:
Device: HBA1
WWN:
Status: Online/Offline
Device: HBA2
WWN:
Status: Online/Offline
++++++++++++++++++++++++++++++++++++++++
$HostList = get-content E:\vmw\GetVMHostList.txt
ForEach($HostName in $HostList)
{
$HostName = $HostName
get-vmhost $HostName | get-annotation -customattribute Chassis
get-vmhosthba -vmhost $HostName -type FibreChannel
}
Write-Host "Done." -foreground Yellow
Out-File C:\ScriptOutput\FCdetails.txt
The ForEach doesn't place anything in the pipeline.
Capture the result in a variable, then send that to the file
$HostList = Get-Content E:\vmw\GetVMHostList.txt
$text = ForEach($HostName in $HostList)
{
$HostName = $HostName
Get-VMHost $HostName | Get-Annotation -customattribute Chassis
Get-VMHostHba -VMHost $HostName -Type FibreChannel
}
Write-Host "Done." -foreground Yellow
$text | Out-File -FilePath C:\ScriptOutput\FCdetails.txt`
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks again LucD.
All working 😃