Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 180923

Adding more functinality to found script that unmounts LUNs.

$
0
0

I found this small and straight forward handy little script by David Stamen (davidstamen.com)
https://davidstamen.com/2015/09/14/using-powercli-to-detach-luns/

 

# PowerCLI Script for detaching luns from a cluster

# @davidstamen

# http://davidstamen.com

 

$LunIDs = "naa.6000000001","naa.600000002"

$Clustername = "MyCluster"

 

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 "Yellow"

        Detach-Disk -VMHost $VMHost -CanonicalName $LUNid

    }

}

https://reddit.com/submit/?url=%2f2015%2f09%2f14%2fusing-powercli-to-detach-luns%2f&resubmit=true&title=Using%20PowerCLI%20to%20Detach%20Luns

This almost does it for me, I still need to connect to every host involved and removed the detached LUNs

Procedure being first SSH to host and then running the CLI commands:

esxcli storage core device detached list

esxcli storage core device detached remove -d naa.6000000001

esxcli storage core device detached remove -d naa.6000000002

and so on.

 

I cant help to think they ought to be a way to add this to David's existing script. Utilizing the $LunIDs and $VMHost that have already been defined.

 

All i seem to be finding are standalone scripts and would appear to be way more convoluted than they need to be.

Any suggestions or pointers?

 

 

?subject=Using%20PowerCLI%20to%20Detach%20Luns&body=%2f2015%2f09%2f14%2fusing-powercli-to-detach-luns%2f


Viewing all articles
Browse latest Browse all 180923

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>