Hello,
I want to unmount and/or mount a RDM disk on a VM plus to change the controller id position.
The script works well but i want to change the scsi position on the Controller (for exampl, change the controller id of an existing disk (0:1) to (1:0)) but i can't find the right command.
# Mount or Umount an RDM disk
$delrdmlist = @()
$addrdmlist = @()
$nom_vm_del = @()
$naaid_del = @()
$nom_vm_add = @()
$naaid_add = @()
$delrdmlist = Import-CSV "C:\Users\Ashar\Documents\RDM\del_vm_rdm_list.csv"
$addrdmlist = Import-CSV "C:\Users\Ashar\Documents\RDM\add_vm_rdm_list.csv"
function Remove_RDM {
foreach ($delrdm in $delrdmlist)
{
$nom_vm_del = $delrdm.name
$naaid_del = $delrdm.naaid
get-vm $nom_vm_del | Get-HardDisk -DiskType "RawVirtual" | Remove-HardDisk -Confirm:$false -DeletePermanently
Write-Host "The RDM $naaid_del unmouted on VM $nom_vm_del" -ForegroundColor Green
}
}
function Add_RDM {
foreach ($addrdm in $addrdmlist)
{
$nom_vm_add = $addrdm.name
$naaid_add = $addrdm.naaid
New-HardDisk -VM $nom_vm_add -DeviceName /vmfs/devices/disks/$naaid_add -DiskType RawVirtual -Persistence persistent -Confirm:$false
Write-Host "The RDM $naaid_add was mounted on VM $nom_vm_add" -ForegroundColor Green
}
}
Write-Host ""
Write-Host "====== vCenter : $vCenterConnected ======" -ForegroundColor Green
Write-Host ""
Write-Host "1 - Unmount RDM"
Write-Host "2 - Mount RDM"
Write-Host ""
Write-Host ""
$choice = Read-Host "Choose your selection "
do {
switch ($choice) {
'1'{
Remove_RDM
}
'2'{
Add_RDM
}
}
} until (($choice -eq '1') -or ($choice -eq '2')
Thank you for your help !
Ashar
You will need to assign a new SCSI controller (New-ScsiController) to the VM, and then use the Controller parameter, with the newly created controller, on the New-Harddisk cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello Luc,
Thank you for your reply.
I want just to set an existing Controller, not to create a new Scsi Controller.
Best regards.
My csv file is like this :
vmname,naaid,SCSIBUSNUMBER,UNITNUMBER
vmtest,naa.60060e800729270000302927000005da,0,4
Something like this Solved: Re: Script for attaching multiple existing disk to... - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello,
I dont' understand the last part of the script.
My wish is to have a script who can add a rdm disk and configure the controller+unitnumber.
Can you help me please?
What don't you understand about that code?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello Luc,
I don't understand this part of the script (sorry i am not an powercli expert) :
# Add the VMDK
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$device = New-Object VMware.Vim.VirtualDisk
$device.Backing = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo
$device.Backing.Filename = $vmdk.datastorepath
$device.UnitNumber = $vmdk.UNITNUMBER
$device.Backing.DiskMode = 'persistent'
$device.ControllerKey = $controller.ExtensionData.Key
$device.Key = -10
$devChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$devChange[0].Device = $device
$devChange[0].Operation = 'add'
$spec.DeviceChange += $devChange
$vm.ExtensionData.ReconfigVM($spec)
How can i adapt this this for my need?
I'm not sure what exactly you want me to do.
The code is attaching a harddisk to a specific controller and with a specific unit number.
Since that functionality is not available through the cmdlet, the script uses the API method.
If you are not experienced with PowerCLI or the vSphere API I don't know how to explain the code to you.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
First and foremost I want to really thank LucD for all of the amazing knowledge that you post on this forum. I am simply amazed at how fast you return Answers on this blog and how you can articulate them so well. I read it daily when I can and use it as my primary learning tool for powercli and powershell.
As for this issue I totally understand the users frustrations.
Not having an easy way to map SCSI IDs to VMs with the New-HardDisk Command-let.
It makes it very hard to deploy solutions like Oracle RAC and Microsoft Failover Clusters.
This same issue forced me to learn PowerShell and PowerCli at a much deeper level.
I created a series of powershell functions just for this reason to fill this gap.
I give all of the programing logic credit to contributors like LucD as I understand the code but not at the level they do.
I was able to reverse engineer code from this site and others to create a series of powershell functions that allow me to Add VM HardDisks using SCSI IDs : VDN : VirtualDeviceNodes.
I used the PowerShell Methodologies learned from Industry Leaders like Jeff Hicks to make these functions.
There is a series of them as they use the PowerShell Way of Each Function should do one specific Task.
I can share with the community.
They have been tested in lab but come without any warranty. I will do my best to help depending on free cycles.
I know they work. They have been tested and used for around 6 months now.
I should have posted them sooner but got busy on some other IT Projects for other clients.
I wanted to finish some help files in the functions and post to github but never got around to it.
They key is they are gold and work !!!!
-RL
Here is a list of function for RDMs I created.
Most of the function rely on another function to gather facts and feed to Disk Functions.
This function I created is called (Get-OraDiskInfo)
It is like gold in oracle RAC Environments when you need to correlate UUIDs and NAAIDs to vdisk :VDNs. Virtual Device Nodes : Scsi IDs.
I have this one in a separate module that I Load.
I will start off by posting this Glue function (Get-OraDiskInfo) and the RDM Functions.
You can play around with them for starters.
Once you get used to the basic AdHoc RDM Function Usage I will upload another wrapper function that uses CSV Input to map out RDMs to VM Nodes.
I added the RDM Functions to zip file and attached.
Just unzip and load the ps1 file in ISE.
Then Start Playing Around in a test environment.
I will try to post some Playbooks with examples if people are interested.
It is a .ps1 file with all of the RDM Functions and the Wrapper Function (Get-OraDiskInfo).
Make sure you Load both Get-OraDiskInfo Function into memory when using Functions that Rely on it.
I would suggest creating a powershell module to load all at once or just load all of the function in ISE Session.
I typically run from ISE in more of an administrator AD Hoc Mode. But will use VSCODE When necessary.
-RL