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.
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
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 ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
Luc, do you have any time to help me with obtaining my desired output?
Rob.
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
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}}
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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