Hi LucD,
I am unable to get the LUN ID as below in the output
below is the complete script
function Detach-Disk{
param(
[VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost]$VMHost,
[string]$CanonicalName
)
$storSys = Get-View $VMHost.Extensiondata.ConfigManager.StorageSystem
$lunUuid = (Get-ScsiLun -VmHost $VMHost | where {$_.CanonicalName -eq $CanonicalName}).ExtensionData.Uuid
$storSys.DetachScsiLun($lunUuid)
}
function Get-DiskState
{
param(
[VMware.VimAutomation.ViCore.Types.V1.Inventory.VMHost]$VMHost,
[string]$CanonicalName
)
$storSys = Get-View $VMHost.Extensiondata.ConfigManager.StorageSystem
$lun = Get-ScsiLun -CanonicalName $CanonicalName -VmHost $VMHost -ErrorAction SilentlyContinue
if(!$lun){'detached'}
else{'attached'}
}
$hostslist = import-csv HostList.csv
$luns = import-csv LunList.csv
$report = @()
foreach ($vmhost in $hostslist){
$hostname=$vmhost.host
write-host "Starting $hostname"
$esx = get-vmhost $hostname
foreach ($lun in $luns){
$naa=$lun.naa
$lunState = Get-DiskState -VMHost $esx -CanonicalName $naa
write-host "Detaching LUN $naa from $esx"
if($lunState -eq 'attached'){
Detach-Disk -vmhost $esx -CanonicalName $naa
}
$report += New-Object PSObject -Property @{
VMHost = $esx.Name
NAA = $naa
PreState = $lunState
}
}
}
$report