And now?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You mean something like this?
$clusterName = 'MyCluster'
Get-CLuster -Name $clusterName | Get-VMHost | %{
$esxcli = Get-EsxCli -VMHost $_
$esxcli.storage.core.device.list() |
Select @{N='ESX';E={$esxcli.VMHost.Name}},Device
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have found another script which is useful, but i am not able to export to CSV or html format, can you do that for me?
also below script doesn't show LUN ID
$esxihosts = Get-VMHost
foreach ($esx in $esxihosts) {
$esxclihost = Get-EsxCli -VMHost $esx
$esxclihost.storage.core.device.list() | where {$_.DeviceType -eq 'Direct-Access'} |
Select @{N='ESX';E={$esx.Name}},
@{N='LUN ID'; E={$d = $_; ((Get-ScsiLun -VmHost $esx | Where {$_.CanonicalName -eq $d.Device}).RuntimeName -split ':' | Select -last 1).TrimStart('L')}},
@{N='Datastore Name'; E={$d = $_; (Get-Datastore -RelatedObject $esx | Where {$_.ExtensionData.Info.Vmfs.Extent.DiskName -eq $d.Device}).Name}},
IsPerenniallyReserved,
Size
}
In vSphere 6 the Runtime property is returned empty for the Get-ScsiLun cmdlet.
But it can be found via another path.
Try like this
$clusterName = 'MyCluster'
$report = Get-Cluster -Name $clusterName | Get-VMHost | %{
$esxcli = Get-EsxCli -VMHost $_
$esxcli.storage.core.device.list() |
Select @{N='ESX';E={$esxcli.VMHost.Name}},Device,
@{N='LUN ID'; E={
$d = $_
if(([Version]$esxcli.VMHost.Version).Major -lt 6){
$lun = Get-ScsiLun -VmHost $esxcli.VMhost | Where {$_.CanonicalName -eq $d.Device}
$runtime = $lun.RuntimeName
}
else{
$lun = $esxcli.VMHost.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object{$_.CanonicalName -eq $d.Device}
$lunUuid = $lun.Uuid
$runtime = ($esxcli.VMHost.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Where-Object{$_.Id -eq $lunUuid}).Path[0].Name
}
$runtime.Split('L')[1]
}}
}
$report
#$report | Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
above script works but i can see only ESX name and LUN serial number but can you add SCSI ID and IsPerenniallyReserved column as well for above script?
"xxxhostname","naa.600507680c8080d948000000000006cb",
"xxxhostname"","naa.600507680c8080d948000000000006cc",
I updated the script above, please try again.
Should show the LUNid as well now
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
now it showing LUN ID but it only shows for one hosts, i have two hosts in cluster, my requirement is I am trying to find out what is the LUN ID per each ESXI and take out Serial number and Size of that lun if they are differ in SCSI ID.
And now?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Lucd
Lucd
Sorry, Can you add few two more column datastore Name and Size of the Lun please?
Try like this
$clusterName = 'MyCluster'
$report = Get-Cluster -Name $clusterName | Get-VMHost | %{
$esxcli = Get-EsxCli -VMHost $_
$esxcli.storage.core.device.list() |
Select @{N='ESX';E={$esxcli.VMHost.Name}},Device,
@{N='LUN ID'; E={
$d = $_
if(([Version]$esxcli.VMHost.Version).Major -lt 6){
$lun = Get-ScsiLun -VmHost $esxcli.VMhost | Where {$_.CanonicalName -eq $d.Device}
$runtime = $lun.RuntimeName
}
else{
$lun = $esxcli.VMHost.ExtensionData.Config.StorageDevice.ScsiLun | Where-Object{$_.CanonicalName -eq $d.Device}
$lunUuid = $lun.Uuid
$runtime = ($esxcli.VMHost.ExtensionData.Config.StorageDevice.MultipathInfo.Lun | Where-Object{$_.Id -eq $lunUuid}).Path[0].Name
}
$runtime.Split('L')[1]
}},
@{N='CapacityGB';E={Get-ScsiLun -CanonicalName $_.Device -VmHost $esxcli.VMHost | Select -ExpandProperty CapacityGB}},
@{N='Datastore';E={
$d = $_
Get-Datastore | where{$_.ExtensionData.Info.Vmfs -and $_.ExtensionData.Info.Vmfs.Extent[0].DiskName -eq $d.Device} |
select -ExpandProperty Name
}}
}
$report | Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Lucd, but again it is showing for one ESXi box, can we pull for all ESXi server in cluster as i said before
do i need to change to?
$report = Get-Cluster -Name $clusterName | Get-VMHost | %{
Yes, I left my test statement for only one ESXi node in there.
I updated the code above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD, I'm over here from the other thread you replied to me re: getting the LUN ID's but I have a mix of 5.1 and 6.0 hosts.
I have tried this version and when I run it there is a warning:
"The Get-EsxCli cmdlet provides a new interface to the ESXCLI functionality.
Use the -V2 parameter to switch to the new cmdlet interface."
then it apparently just sits there and doesn't do anything. I have let it sit for probably 20 mins. I also cannot ctrl-c out of it, have to close powercli.
thoughts?
and thanks a ton for your help.
I'm experiencing the same issue. Did you ever figure this out?
thx-
Did you add the V2 switch on the Get-EsxCli cmdlet?
If yes, did you update all the esxcli commands, the format has changed in V2.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The report shows multiple entries per LUN / per esxi host.
Is there a possibility of having a single row for each LUN with columns for each ESXi host afterwards.
example your RDM script as per this post.
https://www.lucd.info/2010/04/09/lun-report-datastores-rdms-and-node-visibility/
or can this RDM script be modified to show LUN number what we see from Web Client instead of OK in the report against each ESXi server?
If you look in the Comments on that post, more specifically my reply from DECEMBER 21, 2019, you'll see a version that shows the LUNid instead of the "ok" string in each ESXi column.
Is that what you are looking for ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Tried that version but getting below error:
Add-Type : c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(1) : Invalid token 'string' in class, struct, or interface member declaration
c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(1) : >>> public struct LunInfo45625{npublic string ClusterName;
c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(2) : public string CanonicalName;
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:29 char:1
+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(5) : Invalid token 'string' in class, struct, or interface member declaration
c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(4) : public string DSC;
c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(5) : >>> public string SizeGB;ntpublic string ESXi109;ntpublic string ESXi110;n}
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:29 char:1
+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(5) : Invalid token 'string' in class, struct, or interface member declaration
c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(4) : public string DSC;
c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(5) : >>> public string SizeGB;ntpublic string ESXi109;ntpublic string ESXi110;n}
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:29 char:1
+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(5) : Invalid token '}' in class, struct, or interface member declaration
c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(4) : public string DSC;
c:\Users\user\AppData\Local\Temp\14\o4hjkwmg.0.cs(5) : >>> public string SizeGB;ntpublic string ESXi109;ntpublic string ESXi110;n}
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:29 char:1
+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
Add-Type : Cannot add type. Compilation errors occurred.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:29 char:1
+ Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-Type], InvalidOperationException
+ FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
New-Object : Cannot find type [LunInfo45625]: verify that the assembly containing this type is loaded.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:95 char:8
+ $lun = New-Object ("LunInfo" + $rndNum)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
The property 'ClusterName' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:96 char:1
+ $lun.ClusterName = $ClusterName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'ESXi109' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:99 char:1
+ $lun.$esxName = $_.Value[3]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'CanonicalName' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:100 char:25
+ if(!$lun.CanonicalName){$lun.CanonicalName = $_.Value[0]}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'UsedBy' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:101 char:18
+ if(!$lun.UsedBy){$lun.UsedBy = $_.Value[1]}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'SizeGB' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:102 char:18
+ if(!$lun.SizeGB){$lun.SizeGB = [math]::Round($_.Value[2],0)}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'DSC' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:103 char:1
+ $lun.DSC = $_.Value[4]
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'ESXi110' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:99 char:1
+ $lun.$esxName = $_.Value[3]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'CanonicalName' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:100 char:25
+ if(!$lun.CanonicalName){$lun.CanonicalName = $_.Value[0]}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'UsedBy' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:101 char:18
+ if(!$lun.UsedBy){$lun.UsedBy = $_.Value[1]}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'SizeGB' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:102 char:18
+ if(!$lun.SizeGB){$lun.SizeGB = [math]::Round($_.Value[2],0)}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'DSC' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:103 char:1
+ $lun.DSC = $_.Value[4]
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
New-Object : Cannot find type [LunInfo45625]: verify that the assembly containing this type is loaded.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:95 char:8
+ $lun = New-Object ("LunInfo" + $rndNum)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
The property 'ClusterName' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:96 char:1
+ $lun.ClusterName = $ClusterName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'ESXi109' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:99 char:1
+ $lun.$esxName = $_.Value[3]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'CanonicalName' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:100 char:25
+ if(!$lun.CanonicalName){$lun.CanonicalName = $_.Value[0]}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'UsedBy' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:101 char:18
+ if(!$lun.UsedBy){$lun.UsedBy = $_.Value[1]}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'SizeGB' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:102 char:18
+ if(!$lun.SizeGB){$lun.SizeGB = [math]::Round($_.Value[2],0)}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'DSC' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:103 char:1
+ $lun.DSC = $_.Value[4]
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'ESXi110' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:99 char:1
+ $lun.$esxName = $_.Value[3]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'CanonicalName' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:100 char:25
+ if(!$lun.CanonicalName){$lun.CanonicalName = $_.Value[0]}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'UsedBy' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:101 char:18
+ if(!$lun.UsedBy){$lun.UsedBy = $_.Value[1]}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
The property 'SizeGB' cannot be found on this object. Verify that the property exists and can be set.
At D:\script\user\LUN-Mismatch\LUN-Mismatch.ps1:102 char:18