VMware Cloud Community
jtivan
Contributor
Contributor

how to detach rdm disks from cluster simultaneously?

Hi I have such a script. but it detach rdm disks sequentially. tell me how to convert a script so that it simultaneously disables rdm from all cluster hosts

Connect-VIServer "my-vcerver"
$filepath = "D:\scripts\usov_is\naa.csv"
$Clustername = "AZRC"
$LunIDs = @()

Import-Csv $filepath |

foreach {
$LunIDs = $LunIDs + $_.naa

}
function Detach-Disk {
    param(
        [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]$VMHost,
        [string]$CanonicalName    )

    $storSys = Get-View $VMHost.Extensiondata.ConfigManager.StorageSystem
    $lunUuid = (Get-ScsiLun -VmHost $VMHost | where {$_.CanonicalName -eq $CanonicalName}).ExtensionData.Uuid

    $storSys.DetachScsiLun($lunUuid)
}

$ClusterHosts = Get-Cluster $Clustername | Get-VMHost
Foreach ($VMHost in $ClusterHosts)
{
         Foreach($LUNid in $LunIDs)
    {
        Write-Host "Detaching" $LUNid "from" $VMHost -ForegroundColor "Black"
        Detach-Disk -VMhost $VMHost -CanonicalName $LUNid
    }
    
}

3 Replies
LucD
Leadership
Leadership

With the DetachScsiLunEx method (vSphere 6.*) you can detach multiple LUNs in 1 call.

If we use the method in async mode (the _Task extension), it will return immediately.

Connect-VIServer "my-vcerver"

$filepath = "D:\scripts\usov_is\naa.csv"

$Clustername = "AZRC"

$LunIds = Import-Csv $filepath | Select -ExpandProperty naa

function Detach-Disks {

    param(

        [VMware.VimAutomation.ViCore.Impl.V1.Inventory.VMHostImpl]$VMHost,

        [string[]]$CanonicalName    )

    $storSys = Get-View $VMHost.Extensiondata.ConfigManager.StorageSystem

    $lunUuid = (Get-ScsiLun -VmHost $VMHost | where {$CanonicalName -contains $_.CanonicalName}).ExtensionData.Uuid

    $storSys.DetachScsiLunEx_Task($lunUuid)

}

$ClusterHosts = Get-Cluster $Clustername | Get-VMHost

Foreach ($VMHost in $ClusterHosts)

{

    Write-Host "Detaching $($LUNid -join '|') from $VMHost" -ForegroundColor "Black"

    Detach_Disks -VMHost $VMHost -CanonicalName $LunIds

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

timtraceham1
Contributor
Contributor

What format does the .csv file need?  I have my LUN ID from the SAN, 6000d3100138e80000000000000001fd.  Does the naa. need to be in a separate column, or in the same column with the LUN ID, as in naa.6000d3100138e80000000000000001fd?  Do I need a column heading, or just the LUN ID, with the naa. in the front of the ID? 

0 Kudos
LucD
Leadership
Leadership

The CSV needs a column header, named 'naa'.
The value needs to the full canonical name, i.e. naa.6000d3100138e80000000000000001fd

In fact, that is the value the Get-ScsiLun cmdlet returns under the CanonicalName property.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos