PowerCLI novice here... trying to get my head around the correct syntax for reporting properties into a csv file.
I know that the below is all wrong, but it should be easy to understand what I am trying to accomplish. Im just not sure what the correct syntax should be to achieve the desired results (which is just capturing device, type, model, and status to a csv file) .
$report = @()
$info = Get-VMHost | Get-VMHostHba | where {$_.Type -eq "FibreChannel"}
$row = "" | select device, type, model, status
$row.Device = $info | select device
$row.Type = $info | select Type
$row.Model = $info | select Model
$row.Status = $info | select Status
$report += $row
$report | Export-Csv "c:\Temp\results.csv" -NoTypeInformation
############
thanks in advanced for the replies...
Kevin
Try this:
$report = @()
foreach ($esx in get-cluster | get-vmhost | get-view | sort-object name){
foreach($hba in $esx.Config.StorageDevice.HostBusAdapter){
if($hba.GetType().Name -eq "HostFibreChannelHba"){
$row = "" | select Name,WWN,device,model,status
$row.Name = $esx.name
$wwn = $hba.PortWorldWideName
$wwnhex = "{0:x}" -f $wwn
$row.WWN = $wwnhex
$row.device = $hba.device
$row.model = $hba.model
$row.status = $hba.status
$report += $row
}
}
}
$report | export-csv c:\Temp\hbainf-to-host.csv -NoTypeInformation
You can get the required information like this:
Get-VMHost | ` Get-VMHostHba | ` where-Object {$_.Type -eq "FibreChannel"} |` Select-Object -property device,type,model,status | ` Export-Csv "c:\Temp\results.csv" -NoTypeInformation
Regards, Robert
Thanks for the reply Robert. That does answer the question that I asked... thanks.
But what I am ultimately trying to accomplish is to combine multiple commands into 1 csv file. Specifically, I want to incorporate LucD's ESX Fibre - SAN identifier
into the same report. The end result would be a csv report that includes
"-property name,device,type,model,status" along with the wwpn using the code below.
$esx = Get-VMHost | Get-View
foreach($hba in $esx.Config.StorageDevice.HostBusAdapter){
if($hba.GetType().Name -eq "HostFibreChannelHba"){
$wwn = $hba.PortWorldWideName
$wwnhex = "{0:x}" -f $wwn
$wwnhex
}
}
Thanks Robert, I am definately closer
Try this:
$report = @()
foreach ($esx in get-cluster | get-vmhost | get-view | sort-object name){
foreach($hba in $esx.Config.StorageDevice.HostBusAdapter){
if($hba.GetType().Name -eq "HostFibreChannelHba"){
$row = "" | select Name,WWN,device,model,status
$row.Name = $esx.name
$wwn = $hba.PortWorldWideName
$wwnhex = "{0:x}" -f $wwn
$row.WWN = $wwnhex
$row.device = $hba.device
$row.model = $hba.model
$row.status = $hba.status
$report += $row
}
}
}
$report | export-csv c:\Temp\hbainf-to-host.csv -NoTypeInformation
This forum rocks!!!
That's what I was looking for. Thanks sysxperts for tying this together.