VMware Cloud Community
amor123
Enthusiast
Enthusiast

PowerCLI RDM Configuration

I am using vCenter 6.0 ESXi 6.0

I have more than 200 RDM

I must add and remove RDM from the VM(The VM must be created as a shared RDM rather than a single RDM)

There is too much work to do manually

I need a script to add and remove RDM to the VM

Can someone help me?

Reply
0 Kudos
26 Replies
LucD
Leadership
Leadership

That is rather easy with the New-Harddisk cmdlet and the DeviceName parameter, and then later the Remove-Harddisk cmdlet.

Do you have some more info on what exactly you want to do?

Are the canonicalnames of the LUNs available? In a CSV?
Are these RDM to be configured in RawPhysical or RawVirtual?

Do you need two separate scripts? One to add and one to remove the RDM?


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

Reply
0 Kudos
amor123
Enthusiast
Enthusiast

Yes, i need two separate scripts to remove and add

The type must be physical because i need to configure the shared disk

Reply
0 Kudos
LucD
Leadership
Leadership

How is the information provided? In a CSV file?
The script needs the canonicalname of the LUN and the name of the VM.


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

Reply
0 Kudos
amor123
Enthusiast
Enthusiast

Do I have to use a csv file?

Reply
0 Kudos
LucD
Leadership
Leadership

No, but you have to provide the information one way or the other


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

Reply
0 Kudos
amor123
Enthusiast
Enthusiast

it does not matter which way i use it.

Any way I want to do it easily.

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, with a CSV file with this layout

vmName,CanonicalName

vm1,naa.60050123418085af1800000000000010

vm2,naa.60050123418085af1800000000000011

vm3,naa.60050123418085af1800000000000012

You can use this to attach the RDM.

foreach($row in Import-Csv -Path .\rmd.csv -UseCulture){

    New-HardDisk -VM $row.vmName -DeviceName $row.canonicalName -DiskType RawPhysical -Confirm:$false

}

And this to remove it later on.

foreach($row in Import-Csv -Path .\rmd.csv -UseCulture){

    Get-HardDisk -VM $row.vmName -DiskType RawPhysical |

    where{$_.DeviceName -eq $row.canonicalName} |

    Remove-HardDisk -Confirm:$false

}


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

Reply
0 Kudos
amor123
Enthusiast
Enthusiast

Do not have to specify a scsi number?

When I create a shared disk, can I use the same script for setting up an existing disk in the second vm?

Reply
0 Kudos
LucD
Leadership
Leadership

No, not if you don't care which number the disk will  get.


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

Reply
0 Kudos
amor123
Enthusiast
Enthusiast

I'm sorry I can not speak English well.

I need a scsi number...and disk number

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, that is a new requirement.

What about the controller. Do we attach the harddisk to an existing controller, or do we create a new controller?

Looks more and more as if you want something as in Re: Script for attaching multiple existing disk to VM with specific scsi bus number and device numbe...


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

Reply
0 Kudos
amor123
Enthusiast
Enthusiast

I'm sorry I could not at once.

What I want is

Removing RDMs from Existing VMs

Add RDM (physical) to with new controller (physical) and disk number appointed

Add an existing RDM to the second VM

Reply
0 Kudos
LucD
Leadership
Leadership

Ok, let's start with the removal.

Should that script look at all the VMs, or only some?
Are the VMs in the latter case specified in a file? In a CSV?
Do we have to remember the CanonicalName of the RDM we removed?RDM to a

Do we add the RDM back again to the same VM?

But with a different controller?
And where do we get the SCSI id from> Also in a CSV?

And how will the script know the 2nd VM?

Is that information also in the CSV?                                                                                                                                                                                                                                                                   


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

Reply
0 Kudos
amor123
Enthusiast
Enthusiast

In short, it is to remove the RDM for the MSCS configuration of the existing VM and configure the MSCS back into the new VM

Should that script look at all the VMs, or only some?

-Only apply to the required VM

Are the VMs in the latter case specified in a file? In a CSV?

-It should be created in csv if necessary

Do we have to remember the CanonicalName of the RDM we removed?RDM to a

-?? CanonicalName ..I do not know what this is

Do we add the RDM back again to the same VM?

- no. Add it to another VM

But with a different controller? And where do we get the SCSI id from> Also in a CSV?

-It should be created in csv if necessary

And how will the script know the 2nd VM? Is that information also in the CSV?

-It should be created in csv if necessary                        

Reply
0 Kudos
LucD
Leadership
Leadership

When you say "It should be created in csv if necessary" do you mean that the information is available in a CSV or that the script should create a CSV with that information?

In any case, the script will need to find the names of the VMs in the MSCS cluster somewhere.

A canonicalname is the DeviceName of the LUN you attach as a RDM.

See example 2 on the New-Harddisk cmdlet.


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

Reply
0 Kudos
amor123
Enthusiast
Enthusiast

Do we have to remember the CanonicalName of the RDM we removed?RDM to a

- yes

When you say "It should be created in csv if necessary" do you mean that the information is available in a CSV or that the script should create a CSV with that information?

- i need to generate csv via script.

Reply
0 Kudos
LucD
Leadership
Leadership

How will the script know the names of the VMs (old and new)?


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

Reply
0 Kudos
amor123
Enthusiast
Enthusiast

I have to enter the VM name myself

Should I do this with csv?

Reply
0 Kudos
LucD
Leadership
Leadership

Try something like this.

Anything missing?

$vmName = Read-Host -Prompt "Name of the VM"

$newVmName = Read-Host -Prompt "Name of the new VM"

$oldVM = Get-VM -Name $oldVmName

$newVM = Get-VM -Name $newVmName

foreach($hd in (Get-HardDisk -VM $oldVM -DiskType RawPhysical)){

    Remove-HardDisk -HardDisk $hd -Confirm:$false

    $lun = Get-ScsiLun -VmHost $oldVM.VMHost | where{$_.CanonicalName -match $hd.ExtensionData.Backing.LunUuid.substring(10,32)}

    New-HardDisk -VM $newVM -DiskType RawPhysical -DeviceName $lun.ConsoleDeviceName |

    New-ScsiController -BusSharingMode Physical

}


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

Reply
0 Kudos