VMware Cloud Community
zbass11
Contributor
Contributor

need help with PowerCli script to detach RDM devices not datastores

I have seen PowerCli scripts to detach datastores, but I need to detach RDM devices instead.  In a multi-node cluster, it's pretty tedious to go to every host and unmount the RDM device.  Please help -Thanks

0 Kudos
12 Replies
LucD
Leadership
Leadership

Are these RDMs still connected to VMs in that cluster ?

Do you want to a remove of the RDM from the VM followed by a Detach from the ESXi servers in the cluster ?


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

0 Kudos
zbass11
Contributor
Contributor

These RDMs are removed from the VM. I want to unmount/detach the RDM from the ESXi hosts to prevent APD, before I offline lun on Storage. -Thanks in advance for your help

0 Kudos
LucD
Leadership
Leadership

If you have the canonicalnames of these LUNs, you could just use my Detach-Disk function from LUN juggling in vSphere 5.

If you don't have the canonicalnames, then you can first get a report with the script in LUN report – datastore, RDM and node visibility.


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

0 Kudos
zbass11
Contributor
Contributor

This is helpful  LUN juggling in vSphere 5 but, do you still have perform the detach on each esxi host?  Meaning, first connect to host then detach by canonical name?

0 Kudos
LucD
Leadership
Leadership

No, you can be connected to the vCenter.

Get all the ESXi in the cluster, and then call the function for each ESXi host.

Something like this

Get-Cluster -Name MyCluster | Get-VMHost | %{
    Detach-Disk -VMHost $_ -CanonicalName $canonicalname
}


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

0 Kudos
zbass11
Contributor
Contributor

ok will try. I will also run your lun report script.  -Thanks again for your help.  

0 Kudos
DjinjiRinji
Enthusiast
Enthusiast

Hi Luc,

Detach function works great. But I am having same issue as using detach-datastore.

PowerCLI takes lot of time to complete each task.

When I detach many datastores or RDM LUNs across many hosts takes more time to complete the job by powercli than using vcenter client to do it manually.

Hope you can help on this one.

Regards Gui

Kindly mark as solved if your questions are answered.
>>>>>
Guillermo R
LinkedIn: https://www.linkedin.com/in/gramallo
Web: http://bakingclouds.com/
0 Kudos
LucD
Leadership
Leadership

Sorry to hear that.

What exactly are you doing/using for the Detach-Datastore you mention ?


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

0 Kudos
DjinjiRinji
Enthusiast
Enthusiast

Hi Luc,

Thanks for your reply.

I have VMware vSphere PowerCLI 5.1 Release 1 build 793510 on vSphere 5 environment.

Commands below are executed to unmount and detach datastores also your function to detach any LUN used as RDM or not in use.

Get-Datastore $DATASTORE | Unmount-Datastore

Get-Datastore $DATASTORE | Detach-Datastore

To detach RDM

$clustername = ‘ClusterA’,

$canonicalname = 'eui.xxxxxxxxx', 'eui.xxxxxxxxxxxxx'

Get-Cluster -Name $clustername | Get-VMHost | %{ Detach-Disk -VMHost $_ -CanonicalName $canonicalname}

Used this yesterday to detach 12 RDM from 5 hosts cluster and took long time. Same behavior as for datastores.


After unmap LUN from storage all hosts

Rescan-HostsStorage $Host5

.

All lines works and never experienced issues.

Problem is PowerCLI executes the task for each datastore in one host at time and waits until command prompt returns to continue with next one.

It considerably increase time to complete the job using a script against time required to manually do the job from vcenter, especially when I need to work on 30 hosts and 10 datastores/RDM's or more. It could take hours

Our script use functions from this post http://communities.vmware.com/docs/DOC-18008

As you can see in post screenshots tasks are executed by host for each DS.

From vcenter is more dynamic because I can quickly jump between hosts to unmount DS letting vcenter queue all the tasks.

Is there a way to make PowerCLI send all the tasks and let vcenter queue the complete work in tasks queue?

I investigated if this is possible but couldn’t find a way.

Regards Gui

Kindly mark as solved if your questions are answered.
>>>>>
Guillermo R
LinkedIn: https://www.linkedin.com/in/gramallo
Web: http://bakingclouds.com/
0 Kudos
Muchemi
Contributor
Contributor

I have tried this script to remove RDM's

Get-Cluster -Name MyCluster | Get-VMHost | %{
   
Detach-Disk -VMHost $_ -CanonicalName $canonicalname


}


getting the error below


Detach-Disk : The term 'Detach-Disk' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the

path is correct and try again.

At line:1 char:50

+ Get-Cluster -Name $clustername | Get-VMHost | %{ Detach-Disk -VMHost $_ -Canonic ...

+                                                  ~~~~~~~~~~~

0 Kudos
LucD
Leadership
Leadership

Did you include the function from LUN juggling in vSphere 5 in your script ?


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

0 Kudos
HarelH
Contributor
Contributor

You can also take a look at this post -

http://serv.co/blog/detach-all-unused-devices-in-esxi-cluster/

This script detach any unused device, you can comment out any datastore mapping, so only RDMs will be detached.

0 Kudos