VMware Cloud Community
vin01
Expert
Expert
Jump to solution

need host wwn details in the cluster


Hi guys

i need details like

Data center name

cluster name

hostname

hostip

device name like hba 1 and hba2

and its wwn details

i'm using following script but here i am missing datacenter name,cluster name,hostname. Please help me...

Get-Datacenter "testing" | Get-Cluster "test" | Get-VMhost | Get-VMHostHBA -Type FibreChannel | Select VMHost,Device,@{N="WWN";E={"{0:X}"-f$_.PortWorldWideName}} | Sort VMhost,Device

Regards Vineeth.K
1 Solution

Accepted Solutions
ssbkang
Enthusiast
Enthusiast
Jump to solution

Have you tried something like the following:

$datacenter="testing";$cluster="testing";Get-Datacenter -Name $datacenter | Get-Cluster -Name $cluster | Get-VMhost | Get-VMHostHBA -Type FibreChannel | Select @{N="Datacenter";E={$datacenter}},@{N="Cluster";E={$cluster}},VMHost,Device,@{N="WWN";E={"{0:X}"-f$_.PortWorldWideName}} | Sort VMhost,Device | Export-Csv C:\output.csv


It will generate a file called output.csv at C:\

View solution in original post

0 Kudos
13 Replies
ssbkang
Enthusiast
Enthusiast
Jump to solution

Seems like you want an one-line command.

Try this:

$datacenter="testing";$cluster="testing";Get-Datacenter -Name $datacenter | Get-Cluster -Name $cluster | Get-VMhost | Get-VMHostHBA -Type FibreChannel | Select @{N="Datacenter";E={$datacenter}},@{N="Cluster";E={$cluster}},VMHost,Device,@{N="WWN";E={"{0:X}"-f$_.PortWorldWideName}} | Sort VMhost,Device

Sample Output:


Datacenter : testing

Cluster    : testing

VMHost     : testing1.test.com

Device     : vmhba1                                                                                                                                                                                                           

WWN        : ABCDEFGHIJKLNMOP

Datacenter : testing

Cluster    : testing

VMHost     : testing1.test.com

Device     : vmhba2

WWN        : QRSTUVWXYZABCDEF


Hope this helps.

vin01
Expert
Expert
Jump to solution

Hi ssbkang

Thanks a lot for above update

Here when i try to export  to csv its not showing in correct format any changes to be done in script for exporting..if so please help..

Regards Vineeth.K
0 Kudos
ssbkang
Enthusiast
Enthusiast
Jump to solution

Have you tried something like the following:

$datacenter="testing";$cluster="testing";Get-Datacenter -Name $datacenter | Get-Cluster -Name $cluster | Get-VMhost | Get-VMHostHBA -Type FibreChannel | Select @{N="Datacenter";E={$datacenter}},@{N="Cluster";E={$cluster}},VMHost,Device,@{N="WWN";E={"{0:X}"-f$_.PortWorldWideName}} | Sort VMhost,Device | Export-Csv C:\output.csv


It will generate a file called output.csv at C:\

0 Kudos
vin01
Expert
Expert
Jump to solution

yes i have tried.. it is generating but the out is not showing in correct fromat in csv file..

Regards Vineeth.K
0 Kudos
ssbkang
Enthusiast
Enthusiast
Jump to solution

Could you attach a sample output? Not quite sure what you mean by showing incorrect format in .csv file.

0 Kudos
vin01
Expert
Expert
Jump to solution

thanks  for update it worked after removing |Sort VMhost,Device

Regards Vineeth.K
0 Kudos
ssbkang
Enthusiast
Enthusiast
Jump to solution

So that sorting was causing an issue!

0 Kudos
vin01
Expert
Expert
Jump to solution

yup

Regards Vineeth.K
0 Kudos
vin01
Expert
Expert
Jump to solution

Hi

With this script can i get only active adapters wwn details like..

If my host has 4 adapter but only two using i need only that two wwn details..

Regards Vineeth.K
0 Kudos
ssbkang
Enthusiast
Enthusiast
Jump to solution

The following should do:

$datacenter="testing";

$cluster="testing";

Get-Datacenter -Name $datacenter | Get-Cluster -Name $cluster | Get-VMhost | Get-VMHostHBA -Type FibreChannel | where {$_.Status -eq "online"} | Select @{N="Datacenter";E={$datacenter}},@{N="Cluster";E={$cluster}},VMHost,Device,Status,@{N="WWN";E={"{0:X}"-f$_.PortWorldWideName}} | Export-Csv C:\output.csv

Let me know if it doesn't work Smiley Happy

Steven.

vin01
Expert
Expert
Jump to solution

Thanks Steven that worked..But in output for every value it is showing in ""

like this in .csv file

"Datacenter"  "cluster"  etc...

"Test"            "testcluster"

=============================

For better output is it possible to add below string to get-wwn like 00:00:00:00:00

#Go through each row and put : between every 2 digits
   foreach ($item in $list){
  
$item.wwn = (&{for ($i=0;$i-lt$item.wwn.length;$i+=2
  { 
  
$item.wwn.substring($i,2
  }})
-join':'
  }

Regards Vineeth.K
0 Kudos
ssbkang
Enthusiast
Enthusiast
Jump to solution

That's strange, the output I get doesn't come with "".

Well, you found a solution Smiley Happy

0 Kudos
vin01
Expert
Expert
Jump to solution

function Get-WWN {   

    #Set mandatory parameters for cluster and csvnameparam (

    [CmdletBinding()]

    [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelinebyPropertyName=$True)]

    $VMObject,

    [Parameter(Mandatory=$true)]

    [string]$csv

    )

    #Get cluster and all host HBA information and change format from Binary to hex

    $list=$VMObject | Get-VMhost | Get-VMHostHBA -Type FibreChannel | Select VMHost,Device,@{N="WWN";E={"{0:X}"-f$_.PortWorldWideName}} | Sort VMhost,Device

    #Go through each row and put : between every 2 digits

    foreach ($item in $list){

       $item.wwn = (&{for ($i=0;$i-lt$item.wwn.length;$i+=2)  

                        {    

                            $item.wwn.substring($i,2)  

                        }}) -join':'

    }

    #Output CSV to current directory.

    $list | export-csv -NoTypeInformation $csv.csv

}

can any one pls help me to get  below output with above script

Datacenter : testing

Cluster    : testing

VMHost     : testing1.test.com

Device     : vmhba1                                                                                                                                                                                                          

WWN        : AB:CD:EF:GH:IJ:KL

Datacenter : testing

Cluster    : testing

VMHost     : testing1.test.com

Device     : vmhba2

WWN        : AB:CD:EF:GH:IJ:KL


Regards Vineeth.K
0 Kudos