• About me…

ConfigMgr.nl

VMware, Automation and more

  • About me…

Find a datastore or RDM by LUN ID

27-07-2019 PowerCli Script VMware No Comments

Sometimes the storage team wants to clean up their LUNs but they only know the LUN ID. And they ask you, the ESXi admin, where that LUN is used… Not an easy question if you don’t have an administration of your LUNs.

You can use the UI and do some clickin’ but that is sooo much work. So let’s use some PowerCli magic!

# Ask for parameters
$lunid = Read-Host -Prompt "Which LUN ID do you want to find?"
$cluster = Read-Host -Prompt "And in which cluster?"
# Create variable for the first host in the cluster
# (assuming all hosts in the cluster have the same LUNs
$vmhost = (get-cluster $cluster | get-vmhost).Name[0]
$datastorefound = 0
$rdmfound = 0

# Create variable for datastores with the LUN ID
Write-Host
Write-Host "## Creating list of datastores..."
$datastores = Get-Cluster -Name $cluster | Get-Datastore | Select Name,
@{N="LunID";E={
$dev = $_.ExtensionData.Info.Vmfs.Extent[0].DiskName
$esxcli = Get-EsxCli -VMhost $vmhost -V2
$esxcli.storage.nmp.path.list.Invoke(@{'device'=$dev}).RuntimeName.Split(':')[-1].TrimStart('L')}
}

# Search for the LUN ID
Write-Host "## Checking datastores..."
Write-Host
foreach ($datastore in $datastores) {
if ($datastore.LunID -eq $lunid) {
Write-Warning -Message "Datastore found! $($datastore.Name) has ID $lunid"
$datastorefound += 1}
}

if ($datastorefound -eq 0) {Write-Host "No datastores found with LUN ID $lunid"}

# Create variable for RDMs with the LUN ID
Write-Host
Write-Host "## Creating list of RDMs..."
$rdms = Get-Cluster $cluster | Get-VM | Get-Harddisk -DiskType "RawPhysical","RawVirtual" | Select `
@{N="VM";E={$_.Parent.Name}},
Name,
@{N="LunID";E={(Get-ScsiLun -VmHost $vmhost -CanonicalName $_.ScsiCanonicalName).RuntimeName.Split(':')[-1].TrimStart('L')}}

# Search for the LUN ID
Write-Host "## Checking RDMs..."
foreach ($rdm in $rdms) {
if ($rdm.LunID -eq $lunid) {
Write-Warning -Message "RDM found! $($rdm.VM) has RDM with Lun ID $lunid"
$rdmfound += 1}
}

if ($rdmfound -eq 0) {Write-Host "No RDMs found with LUN ID $lunid"}
findidlunpowercli

vCenter not using SMTP smarthost but DNS

It's official!! vExpert 2019

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Reporting on your Windows Server backup
  • Testing Script Runtime Service for vSphere – part 1
  • Using ADFS with vCenter 7
  • Network Port Diagram vSphere
  • Joining ESXi hosts to AD using Authentication Proxy in vCenter 7 (updated 04-12-2020)
  • Windows Server 2019 customization issue
  • Packer and WinRM – mystery resolved
  • Using LDAPS with vCenter and AD
  • Backup your homelab… for free!
  • Remediation did not succeed

Archives

Categories

AnyLinq (1) Azure (2) ConfigMgr (8) DIY (4) PowerCli (8) Powershell (9) SCCM (9) Script (12) Solutions (16) System Center (3) VMware (30) vRealize Automation (1) vRealize Orchestrator (1)

Jeroen BurenFollow

Jeroen Buren
Retweet on TwitterJeroen Buren Retweeted
Annemiek73Annemiek Meijer@Annemiek73·
16 Jan

Running man kan altijd! Ook tijdens #VVAL2021 @VriendvanAmstel #RunningMan #VVALS

Reply on Twitter 1350537030879608833Retweet on Twitter 13505370308796088332Like on Twitter 135053703087960883327Twitter 1350537030879608833
Retweet on TwitterJeroen Buren Retweeted
PowerCLIVMware PowerCLI@PowerCLI·
11 Jan

Do check out the SRS roadmap here. Feel free to influence the roadmap by submitting your requests. https://github.com/vmware/script-runtime-service-for-vsphere/projects/2 https://twitter.com/PowerCLI/status/1337370157551796225

VMware PowerCLI@PowerCLI

Introduction to Script Runtime Service (SRS) for vSphere https://blogs.vmware.com/PowerCLI/2020/12/introduction-to-script-runtime-service-srs-for-vsphere.html

Reply on Twitter 1348606798492618752Retweet on Twitter 13486067984926187524Like on Twitter 13486067984926187528Twitter 1348606798492618752
jeroen_burenJeroen Buren@jeroen_buren·
7 Jan

New blogpost about Script Runtime Service for vSphere.
https://configmgr.nl/2021/01/07/testing-script-runtime-service-for-vsphere-part-1/

#VMware #vSphere #SRS #PowerCLI

Reply on Twitter 1347191971002118144Retweet on Twitter 1347191971002118144Like on Twitter 1347191971002118144Twitter 1347191971002118144
jeroen_burenJeroen Buren@jeroen_buren·
18 Dec

Nice!! https://www.formula1.com/en/latest/article.breaking-perez-to-partner-verstappen-at-red-bull-in-2021-as-albon-becomes.21qHfmHAyfzAjVHT3PfVBd.html

Reply on Twitter 1339935240069001218Retweet on Twitter 1339935240069001218Like on Twitter 13399352400690012181Twitter 1339935240069001218
Retweet on TwitterJeroen Buren Retweeted
vRealizeAutovRealize Automation@vRealizeAuto·
16 Dec

#vRA x Terraform part 1 — #Cloud Automation Essentials☁️

Check out this blog to explore how you can use vRealize Automation and Terraform in effective ways.👍 https://bit.ly/3r2sLxE

Reply on Twitter 1339261564931727368Retweet on Twitter 13392615649317273686Like on Twitter 13392615649317273685Twitter 1339261564931727368
Load More...
Proudly powered by WordPress | Theme: Doo by ThemeVS.