Below is a script that does exactly what I want but I need to make some changes to it and need help adding the needed lines. I will like to add a line to show the LUN ID's for each storage LUN on each hosts and also add a line for WWN names of the hosts as well. Below is the script.
Thanks.
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) {
"" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
@{N="VM CPU Core#";E={$vm.NumCPU}},
@{N="Datacenter";E={$Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="Host";E={$vm.VMHost.Name}},
@{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
@{N="VMDKpath";E={$HardDisk.FileName}},
@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},
@{N="Drive Size";E={$HardDisk.CapacityGB}}
}
}
}
}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "c:\scripts\reports\report.csv"
While retrieving that info is not too hard, how do you want to show this in the output objects.
The script will produce an object (or line in the CSV file) per harddisk.
Do you want to add that LUN info on each harddisk line ?
I think it would be more readable if you collect that LUN info in a separate CSV.
What do you think ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for you response. I will like to have both meaning LUN ID on the main list and also separate so that I can compare or use the separate one for other analysis.
Forgot to add that yes I will want the LUN info on each harddisk line.
To make sure I get that, you want to list each LUN and all the HBA WWN on the ESXi server on the harddisk line ?
That will be an overcrowded line I suspect.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
They want a complete report and I tried to let them know but they insisted. Like I mentioned before, I will like both scenarios and will separate when needed.
Thanks
LuCD, any update on this?
Try it like this.
Note, since you didn't specify which WWN you want to include in the report, I took the Target WWN.
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name))
{
$ds = Get-Datastore -Name ($HardDisk.FileName.Split("]")[0].TrimStart("[")) |
Select -First 1
$dsLun = @()
$dsLunID = @()
$dsWwwn = @()
Get-ScsiLun -Datastore $ds | Sort-Object -Property CanonicalName -Unique | %{
$dsLun += $_.CanonicalName
$dsLunID += $_.RunTimeName.Split(':')[-1].Trim('L')
}
$esx = Get-VMHost -Name $vm.VMHost.Name
$lunKey = @()
$lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun |
where {$dsLun -contains $_.CanonicalName} | %{$_.Key}
$lunWWN = @()
$lunWWN = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun |
where {$lunKey -contains $_.Lun} | %{
$_.Path | %{"{0:x}" -f $_.Transport.NodeWorldWideName}
} | Sort-Object -Unique
"" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
@{N="VM CPU Core#";E={$vm.NumCPU}},
@{N="Datacenter";E={$Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="Host";E={$vm.VMHost.Name}},
@{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$ds.Name}},
@{N="LUN";E={[string]::Join(',',$dsLun)}},
@{N="LUNID";E={[string]::Join(',',$dsLunId)}},
@{N="LUNWWN";E={[string]::Join(',',$lunWWN)}},
@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
@{N="VMDKpath";E={$HardDisk.FileName}},
@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},
@{N="Drive Size";E={$HardDisk.CapacityGB}}
}
}
}
}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "c:\scripts\reports\report.csv"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I ran the script and it errored out on me. Attached is the error.
It looks like you didn't do a Connect-VIserver before you ran the script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Just took a lot at the error and spotted that. My bad.
Just restarted it again. I think it will take a couple of hours as I started one on another sever about 4 hours ago.
Hi LucD,
The cript seems to be running for more than 6 hours. I will like to remove some lines from it and just have it get me information about VM hosts, VM's, WWN names of the hosts and the LUN ID of whatever is presented from the storage array. What I'm trying to get is the LUN ID that I can tie to each VM through the host. We are trying to identify what VM and hosts are tied to specific LUN iD's. Below is the script;
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name))
{
$ds = Get-Datastore -Name ($HardDisk.FileName.Split("]")[0].TrimStart("[")) |
Select -First 1
$dsLun = @()
$dsLunID = @()
$dsWwwn = @()
Get-ScsiLun -Datastore $ds | Sort-Object -Property CanonicalName -Unique | %{
$dsLun += $_.CanonicalName
$dsLunID += $_.RunTimeName.Split(':')[-1].Trim('L')
}
$esx = Get-VMHost -Name $vm.VMHost.Name
$lunKey = @()
$lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun |
where {$dsLun -contains $_.CanonicalName} | %{$_.Key}
$lunWWN = @()
$lunWWN = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun |
where {$lunKey -contains $_.Lun} | %{
$_.Path | %{"{0:x}" -f $_.Transport.NodeWorldWideName}
} | Sort-Object -Unique
"" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
@{N="VM CPU Core#";E={$vm.NumCPU}},
@{N="Datacenter";E={$Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="Host";E={$vm.VMHost.Name}},
@{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$ds.Name}},
@{N="LUN";E={[string]::Join(',',$dsLun)}},
@{N="LUNID";E={[string]::Join(',',$dsLunId)}},
@{N="LUNWWN";E={[string]::Join(',',$lunWWN)}},
@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
@{N="VMDKpath";E={$HardDisk.FileName}},
@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},
@{N="Drive Size";E={$HardDisk.CapacityGB}}
}
}
}
}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "c:\scripts\reports\report.csv"
That is not what you replied when I asked this :smileycry:
To recap, you want to see the LUN that is behind the virtualdisk that is connected to the VM ?
Do these virtualdisks all reside on datastores, or are there RDMs in there ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
My Bad LucD. Too many things on my mind. 🙂
Yes I will like to see the LUN that is behind the virtualdisks that are connected to the VM and for the other question, most VM's reside on datastores and the RDM's are exchange and DB servers.
🙂
LucD,
Any update on this?
Thanks,
Hi LucD,
Below is the updated script which I modified. I just want it to give me the LUN ID's of the storage array mapped to each ESX and what VM's are associated with it. Let me know if it's correct.
Thanks,
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name))
{
$ds = Get-Datastore -Name ($HardDisk.FileName.Split("]")[0].TrimStart("[")) |
Select -First 1
$dsLun = @()
$dsLunID = @()
$dsWwwn = @()
Get-ScsiLun -Datastore $ds | Sort-Object -Property CanonicalName -Unique | %{
$dsLun += $_.CanonicalName
$dsLunID += $_.RunTimeName.Split(':')[-1].Trim('L')
}
$esx = Get-VMHost -Name $vm.VMHost.Name
$lunKey = @()
$lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun |
where {$dsLun -contains $_.CanonicalName} | %{$_.Key}
$lunWWN = @()
$lunWWN = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun |
where {$lunKey -contains $_.Lun} | %{
$_.Path | %{"{0:x}" -f $_.Transport.NodeWorldWideName}
} | Sort-Object -Unique
"" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="Datacenter";E={$Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="Host";E={$vm.VMHost.Name}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$ds.Name}},
@{N="LUN";E={[string]::Join(',',$dsLun)}},
@{N="LUNID";E={[string]::Join(',',$dsLunId)}},
@{N="LUNWWN";E={[string]::Join(',',$lunWWN)}},
@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
@{N="VMDKpath";E={$HardDisk.FileName}},
@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-
flat.")}).size/1GB}},
@{N="Drive Size";E={$HardDisk.CapacityGB}}
}
}
}
}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "c:\temp\WWNCF03-LUNIDreport.csv"
LucD,
Any updates?
Hi LuCD,
greetings !!
how i can get the drive letter of the LUN/VMDK with command?
please share command or script if you have.
regards,
Deepak
Hey all,
How can I include the Guest OS?
Thanks