Hi Everyone,
i'm looking for a Powercli Script to be able to attach/Create Existing RDM disk on a second node of a vm cluster.
Basically the script should add a new existing disk on the second VM and the path of the disk must be the pointer of the first VM.
The Steps for the script are following :
1. Takes note of what the RDM paths are and then removes all RDMs from A and B , not deletes off the disk, just removes from configuation
2. Powers down both VMs
3. SVmotions vms to new storage
4. Puts the RDMS back that were removed in step one to node A and B
4. Reads a txt file with naa ids and creates Physical rdms from all of them on node A as well as creating an LSI controller in physical bus sharing mode and assigning a SCSI controller id.
5. Creates the same RDMs on node B that we just made on node A but uses the existing pointer and the same SCSI id.
6. Powers up Node A, waits 20 seconds then powers up node B
I've searched the forums and what I've found doesn't really work for me.
Thanks in advance.
Best Regards,
Ben
What do you already have?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
i attached the script file in this reply.
There u can find where i stopped so far.
Best Regards,
Ben
# START MOD VARIABILE
$VMName="VMNAME";$DiskName="Hard disk 2";$DeviceName="/vmfs/devices/disks/naa.XXXXXXXXXXXXXXXXXXXXXXX";$DatastorePath="[DS_NAME] VMFOLDER/VMNAME_2.vmdk";
$NewBusNumber="3";$NewUnitNumber="7";
# END MOD VARIABILI
function Get-VMWareSCSI($params){ $VMName=$params[0]; $DiskName=$params[1];
$target=(Get-HardDisk -vm $VMName -Name $DiskName);
#CALCOLO COLONNA 1 $COLL1=$target| Select @{N='SCSIid';E={$hd = $_; $ctrl = $hd.Parent.Extensiondata.Config.Hardware.Device | where{$_.Key -eq $hd.ExtensionData.ControllerKey}; "$($ctrl.BusNumber)" }} $COLL1=$COLL1.SCSIid;
#CALCOLO COLONNA 2
$COLL2=$target.ExtensionData.UnitNumber
return @($COLL1,$COLL2);}function New-VMWareDisk($params){ $VMName=$params[0]; $DeviceName=$params[1]; $hd = @() $hd += New-HardDisk -VM $VMName -DiskType RawPhysical -DeviceName $DeviceName; New-ScsiController -HardDisk $hd -BusSharingMode Physical -Type VirtualLsiLogicSAS; }function Set-VMWareHDUnitNumber($params){ $VMName=$params[0]; $DiskName=$params[1]; [int]$UnitN=$params[2];
$vm= Get-VM $VMName; $hd=Get-HardDisk -VM $VMName -Name $DiskName; $spec = New-Object VMware.Vim.VirtualMachineConfigSpec; $spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec; $spec.deviceChange[0].operation = "edit"; $spec.deviceChange[0].device=$hd.ExtensionData; $spec.deviceChange[0].device.UnitNumber=$UnitN; $vm.ExtensionData.ReconfigVM_Task($spec);}### EDIT #function Set-VMWareHDBusNumber($params){ $VMName=$params[0]; $DiskName=$params[1]; [int]$BusN=$params[2]; <# $vm= Get-VM $VMName; $hd=(Get-HardDisk -vm $VMName -Name $DiskName) | ?{$_.Parent.Extensiondata.Config.Hardware.Device.Key -eq $_.ExtensionData.ControllerKey}; $controlKey=$hd.ExtensionData.ControllerKey; $spec = New-Object VMware.Vim.VirtualMachineConfigSpec; $spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec; $spec.deviceChange[0].operation = "edit"; $BusN=$hd.Parent.ExtensionData.Config.Hardware.Device | ? {($_.BusNumber -eq $BusN) -and ($_.SharedBus -eq "physicalSharing")}; $spec.deviceChange[0].device=$BusN; $vm.ExtensionData.ReconfigVM_Task($spec); #> $vm= Get-VM $VMName; $hd=(Get-HardDisk -vm $VMName -Name $DiskName) | ?{$_.Parent.Extensiondata.Config.Hardware.Device.Key -eq $_.ExtensionData.ControllerKey}; #$hd=(Get-HardDisk -vm $VMName -Name $DiskName); $controlKey=$hd.ExtensionData.ControllerKey; $spec = New-Object VMware.Vim.VirtualMachineConfigSpec; $spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec; $spec.deviceChange[0].operation = "edit"; $spec.deviceChange[0].device=$hd.Parent.ExtensionData.Config.Hardware.Device | ? {$_.Key -eq $controlKey}; $spec.deviceChange[0].device.BusNumber=$BusN; #Write-Host $spec; $vm.ExtensionData.ReconfigVM_Task($spec);
}
#IMPORT MODULI VMWAREClear-Host;Import-Module "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1" -Force -ErrorAction SilentlyContinue;Clear-Host;
#VCENTER CONNECTconnect-viserver -server "grps-vc6-pv01.cariprpc.it" -User j44839@cariprpc.it -Password Produzione9 | Out-Null
#VISUALIZZA BUSNUMBER:UNITNUMBER$scsiID=Get-VMWareSCSI($VMName,$DiskName);#Write-Host $scsiID[0];#Write-Host $scsiID[1];
$A=$scsiID[0];$B=$scsiID[1];
Write-Host "VMName $VMName SCSI($A : $B)"Write-Host " ";#Write-Host "Reconfig $VMName SCSI($NewBusNumber : $NewUnitNumber)"Write-Host "Reconfig $VMName SCSI($NewBusNumber : $NewUnitNumber)"
#CREA UN HD AD UNA VM ASSOCIANDO UN DEVICE NAME ESISTENTE#New-VMWareDisk($VMName,$DeviceName);
#SETTA BUSNUMBER (COL 1) ***** DA TESTARE#Set-VMWareHDBusNumber($VMName,$DiskName,$NewBusNumber,$NewUnitNumber);
#SETTA UNITNUMBER (COL 2)Set-VMWareHDUnitNumber($VMName,$DiskName,$NewUnitNumber);
$scsiID=Get-VMWareSCSI($VMName,$DiskName);$A=$scsiID[0];$B=$scsiID[1];
Write-Host "VMName $VMName SCSI($A : $B)";
And where is the problem?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The Problem is that i can't find the way to attach the RDM disk from Node 1 (VM1) to the second Node (VM2) or in easy words, the RDM Pointer
Basically i'm stuck in the point :
Creates the same RDMs on node B that we just made on node A but uses the existing pointer and the same SCSI id.
This will create a RDM on VM1, and then create a same RDM on VM2.
It will also make sur ethe unitnumber of the RDM is the same on both VMs.
$vmName1 = 'VM1'
$vmName2 = 'VM2'
$vm1 = Get-VM -Name $vmName1
$vm2 = Get-VM -Name $vmName2
# Find LUN
$lun = Get-ScsiLun -CanonicalName $canonicalName -VmHost $vm1.VmHost
# Attach RDM on VM 1
$hd1 = New-HardDisk -VM $vm1 -DiskType RawPhysical -DeviceName $lun.ConsoleDeviceName
$ctrl1 = New-ScsiController -HardDisk $hd -Type VirtualLsiLogicSAS -BusSharingMode Physical
# Attach RDM on VM 2
$hd2 = New-HardDisk -VM $vm2 -DiskPath $hd1.FileName
$ctrl2 = New-ScsiController -HardDisk $hd2 -Type VirtualLsiLogicSAS -BusSharingMode Physical
$hd2 = Get-HardDisk -Id $hd2.Id -VM $vm2
# Set HD2 unit number to same as HD1
$devChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$devChange.Operation = 'edit'
$devChange.Device = $hd2.ExtensionData
$devChange.Device.UnitNumber = $hd1.ExtensionData.UnitNumber
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.DeviceChange += $devChange
$vm2.ExtensionData.ReconfigVM($spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot for the quick reply.
ill have it tested soon and if it works, ill have u delievered a nice bottle of italian wine
Best Regards.
Ben
if possible to specify the scsi bus number and unit number something like below and increment number for next device.
scsi:1:0 -- > 'naa.1234cfc000000b7850d62c3d54c46789'
Have a look at Solved: RDM Disk with Multiwriter - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference