VMware Cloud Community
kjones12
Contributor
Contributor
Jump to solution

Correct syntax for powercli reporting (csv format)

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

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
sysxperts
Enthusiast
Enthusiast
Jump to solution

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

Paul Valentino - VCP, EMCCA - @sysxperts @vcommunitytrust - Help the vCommunity one certification at a time! http://www.vcommunitytrust.org/ http://igg.me/p/212476?a=1091980

View solution in original post

0 Kudos
4 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

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

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
kjones12
Contributor
Contributor
Jump to solution

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 Smiley Happy

0 Kudos
sysxperts
Enthusiast
Enthusiast
Jump to solution

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

Paul Valentino - VCP, EMCCA - @sysxperts @vcommunitytrust - Help the vCommunity one certification at a time! http://www.vcommunitytrust.org/ http://igg.me/p/212476?a=1091980
0 Kudos
kjones12
Contributor
Contributor
Jump to solution

This forum rocks!!!

That's what I was looking for. Thanks sysxperts for tying this together.

0 Kudos