Hi all,
I know this is old hat stuff as I saw an earlier blog which revolved around what I am trying to achieve here
So, I am trying to retrieve all RDM perennially reserved values per host per vcenter server
I think I have managed to make the script work in regards to it pulling the RawPhysical and RawVirtual disktype per vm and grab the unique values of these and then export these values to a .csv file
I have been asked however if I can also retrieve the LUN of each RDM, I have looked into how to get the LUN value however cannot see how I can place that within my current script
Any help would be much appreciated, script attached as I cant seem to paste into here
Many thanks in advance
You could do something like this
$Cred = Get-Credential -UserName mjclark_a@computacenter.com -Message 'Enter Password for vCenter Servers'
foreach ($VC in $VCenters) {
Write-Host 'Connecting to Vcenter Server '$VC -ForegroundColor Green
Connect-VIServer -Server $VC -Credential $Cred
foreach ($dc in Get-Datacenter) {
foreach ($cluster in Get-Cluster -Location $dc) {
foreach ($esx in Get-VMHost -Location $cluster) {
foreach ($rdm in Get-VM -Location $esx | Get-HardDisk -DiskType RawPhysical, RawVirtual) {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.storage.core.device.list.Invoke(@{device = "$($rdm.ScsiCanonicalName)" }) |
Select-Object @{N = 'Datacenter'; E = { $dc.Name } },
@{N = 'Cluster'; E = { $cluster.Name } },
@{N = 'VMHost'; E = { $esx.Name } },
@{N = 'VM'; E = { $vm.Name } },
@{N = 'HardDisk'; E = { $rdm.Name } },
@{N = 'CanonicalName'; E = { $rdm.ScsiCanonicalName } },
@{N = 'LUN'; E = { ($esxcli.storage.core.path.list.Invoke(@{device = $rdm.ScsiCanonicalName })).RuntimeName.Split('L')[1] } },
@{N = 'PereniallyReserved'; E = { $_.IsPerenniallyReserved } }
}
}
}
Write-Host 'Disconnecting from vCenter Server '$VC -ForegroundColor Cyan
Disconnect-VIServer $VC -confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Isn't that what you have in $naa.
Or what do you mean by LUN?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thanks for replying, basically as well as the raw naa ref ID I also would like the LUNid decimal value stored in vcenter
I think the command to do this is something along the lines below,
get-scsilun -vmhost *.vmhost -canonicalname *.hddisplayname
*.runtimename.substring(*.runtimename.lastindexof("L")+1)
This I borrowed from a previous article:
https://communities.vmware.com/thread/514090
Apologies, as you can tell my powercli is extremely poor
You could do something like this
$Cred = Get-Credential -UserName mjclark_a@computacenter.com -Message 'Enter Password for vCenter Servers'
foreach ($VC in $VCenters) {
Write-Host 'Connecting to Vcenter Server '$VC -ForegroundColor Green
Connect-VIServer -Server $VC -Credential $Cred
foreach ($dc in Get-Datacenter) {
foreach ($cluster in Get-Cluster -Location $dc) {
foreach ($esx in Get-VMHost -Location $cluster) {
foreach ($rdm in Get-VM -Location $esx | Get-HardDisk -DiskType RawPhysical, RawVirtual) {
$esxcli = Get-EsxCli -VMHost $esx -V2
$esxcli.storage.core.device.list.Invoke(@{device = "$($rdm.ScsiCanonicalName)" }) |
Select-Object @{N = 'Datacenter'; E = { $dc.Name } },
@{N = 'Cluster'; E = { $cluster.Name } },
@{N = 'VMHost'; E = { $esx.Name } },
@{N = 'VM'; E = { $vm.Name } },
@{N = 'HardDisk'; E = { $rdm.Name } },
@{N = 'CanonicalName'; E = { $rdm.ScsiCanonicalName } },
@{N = 'LUN'; E = { ($esxcli.storage.core.path.list.Invoke(@{device = $rdm.ScsiCanonicalName })).RuntimeName.Split('L')[1] } },
@{N = 'PereniallyReserved'; E = { $_.IsPerenniallyReserved } }
}
}
}
Write-Host 'Disconnecting from vCenter Server '$VC -ForegroundColor Cyan
Disconnect-VIServer $VC -confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD, this worked perfectly!