ConfigMgr

VMware, Azure and Automation

Find a datastore or RDM by LUN ID

27 juli 2019 PowerCli Script VMware

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

Recent Posts

  • Using API for Aria OPS Chargeback
  • Unable to set reservation on Org VDC
  • Veeam Tweaks
  • VCF Anyone? Get your license for free…
  • Configure Entra ID as Cloud Director IdP

Recent Comments

Geen reacties om te tonen.

Archives

  • april 2025
  • maart 2025
  • november 2024
  • oktober 2024
  • januari 2024
  • november 2023
  • oktober 2023
  • september 2023
  • juni 2023
  • mei 2023
  • april 2023
  • november 2022
  • maart 2021
  • februari 2021
  • januari 2021
  • november 2020
  • oktober 2020
  • september 2020
  • juli 2020
  • juni 2020
  • april 2020
  • maart 2020
  • februari 2020
  • oktober 2019
  • september 2019
  • juli 2019
  • juni 2019
  • mei 2019
  • maart 2019
  • februari 2019
  • januari 2019
  • december 2018
  • november 2018
  • april 2018
  • januari 2018
  • juli 2017
  • juni 2017
  • mei 2017

Categories

  • AnyLinq
  • Azure
  • Cloud Director
  • ConfigMgr
  • DIY
  • HomeAssistant
  • Microsoft
  • PowerCli
  • Powershell
  • SCCM
  • Script
  • Solutions
  • System Center
  • Veeam
  • VMware
  • vRealize Automation
  • vRealize Orchestrator
Proudly powered by WordPress | Theme: Doo by ThemeVS.