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
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:\
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.
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..
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:\
yes i have tried.. it is generating but the out is not showing in correct fromat in csv file..
Could you attach a sample output? Not quite sure what you mean by showing incorrect format in .csv file.
thanks for update it worked after removing |Sort VMhost,Device
So that sorting was causing an issue!
yup
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..
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
Steven.
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':'
}
That's strange, the output I get doesn't come with "".
Well, you found a 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