Automation

 View Only
  • 1.  Script to output WWN Datacenter Cluster Host

    Posted Jun 25, 2013 03:57 PM

    Hi All,

    I am looking to create a script to output:

    WWN with WWP, Datacenter, Cluster, Host

    Not sure how to start with this one. I'm assuming I would start by using Get-Datacenter and then get-content from there.

    Any help much appreciated,

    Rob.



  • 2.  RE: Script to output WWN Datacenter Cluster Host

    Posted Jun 25, 2013 04:36 PM

    Since WWN can be retriever for HBA and/or LUN, you could do

    foreach($dc in Get-Datacenter){

       foreach($cluster in Get-Cluster -Location $dc){

          foreach($esx in Get-VMHost -Location $cluster){

    ...

          }

       }

    }

    In the inner loop you could then get the HBA and/or LUN of the ESXi and extract the WWN.

    Is that what you are looking for ?



  • 3.  RE: Script to output WWN Datacenter Cluster Host

    Posted Jun 25, 2013 05:12 PM

    I think thats the one. The output needs to look like this:

    WWN, Datacenter, Cluster, Host

    20010025B5331E1F 20000025B5122B1F, VI_25Metro, SVCuster02, ucs12.vi.local

    20010025B5331E1F 20000025B5122A1F, VI_25Metro, SVCuster02, ucs12.vi.local

    20010025B5331E0F 20000025B5122B0F, VI_25Metro, SVCuster02, ucs11.vi.local

    Thanks again.



  • 4.  RE: Script to output WWN Datacenter Cluster Host

    Posted Jul 09, 2013 09:25 PM

    Luc, do you have any time to help me with obtaining my desired output?

    Rob.



  • 5.  RE: Script to output WWN Datacenter Cluster Host
    Best Answer

    Posted Jul 10, 2013 12:47 AM

    Rob,

    You can try the following code. It should be a pretty good starter point at the very least. I don't have a FC HBA in my home lab to work out any kinks with the WWN info so that'll have to wait until tomorrow.

    $vmhosts = Get-VMHost

    $HBAInfo = @()

    Foreach ($vmhost in $vmhosts) {

        $HBAs = $vmhost | Get-VMHostHba -Type FibreChannel

        $DC = (Get-Datacenter -VMHost $vmhost).Name

        $Cluster = (Get-Cluster -VMHost $vmhost).Name

        Foreach ($HBA in $HBAs) {

            $Details = "" | Select WWN, Datacenter,Cluster,Host

            $Details.WWN = $HBA.PortWorldWideName

            $Details.Datacenter = $DC

            $Details.Cluster = $Cluster

            $Details.Host = $vmhost.Name

            $HBAInfo += $Details

        }

    }

    $HBAInfo



  • 6.  RE: Script to output WWN Datacenter Cluster Host

    Posted Jul 10, 2013 10:45 AM

    Here is my revised code that gets everything and was checked to work. LucD's works just as well if you want to use his with one caveat that probably won't apply. If you happen to have a host that is not in a cluster (very few cases I'm sure that you would set things up this way) it will not return any results for that host.


    $vmhosts = Get-VMHost

    $HBAInfo = @()

    Foreach ($vmhost in $vmhosts) {

        $HBAs = $vmhost | Get-VMHostHba -Type FibreChannel

        $DC = (Get-Datacenter -VMHost $vmhost).Name

        $Cluster = (Get-Cluster -VMHost $vmhost).Name

        Foreach ($HBA in $HBAs) {

            $Details = "" | Select WWN, WWP, Datacenter, Cluster, Host

            $Details.WWN = "{0:x}" -f $HBA.NodeWorldWideName

            $Details.WWP = "{0:x}" -f $HBA.PortWorldWideName

            $Details.Datacenter = $DC

            $Details.Cluster = $Cluster

            $Details.Host = $vmhost.Name

            $HBAInfo += $Details

        }

    }

    $HBAInfo



  • 7.  RE: Script to output WWN Datacenter Cluster Host

    Posted Jul 10, 2013 06:01 AM

    Sure, try something like this

    foreach($dc in Get-Datacenter){
     
    foreach($cluster in Get-Cluster -Location $dc){
       
    foreach($esx in Get-VMHost -Location $cluster){
         
    Get-VMHostHba -VMHost $esx -Type FibreChannel |
         
    Select @{N="DC";E={$dc.Name}},@{N="Cluster";E={$cluster.Name}},
           
    @{N="Host";E={$esx.Name}},Name,
           
    @{N="HBA Node WWN";E={"{0:x}" -f $_.NodeWorldWideName}},
           
    @{N="HBA Port WWN";E={"{0:x}" -f $_.PortWorldWideName}}
        }
      }
    }