Hi all,
I’m trying to use below script for our SRDF remote replication.I have got the all useful information to export the csv report.
We have scsi controller 0 with OS disk on VMDK, we want to add scsi controller 1 or controller 2,3,4 with physical bus sharing with multiple RDMs on scsi 1:0, 1:1, 1:2 or scsi 2:0, 2:1, 2:3 and like this.
The VMs are member of a MS-SQL (MSCS) or oracle (RAC).
On the target site,
first step (remove-rdm.ps1 script) to remove the unavailable RDM from VMs,
second step (add-rdm.ps1 script) to import the report.csv and use the data to attach the RDM for the first VM,
third step to export the sharedisk.csv include first VM Diskfile like "[datastoreDC] test01/test_3.vmdk",
fourth step (add-exsting-rdm.ps1 script) to read the sharedisk.csv and use the diskpath to add the shared rdm file for the rest of VMs.
I’m having difficulty importing the CSV and assigning the suitable SCSI(x:y) to the RDM go back to its VM.
I can see the errors about null argument and methods.
Could you help me please? Thanks in advance.
report.csv
"VM","Canonical","UnitNr","HDLabel","SCSIID","HDMode","VMHost"
"test01","naa.60000970000495700176533030463635","1","Hard disk 2","SCSI(1:1)","physicalMode","192.168.85.130"
"test01","naa.60000970000495700176533030463636","2","Hard disk 3","SCSI(1:2)","physicalMode","192.168.85.130"
"test02","naa.60000970000495700176533030463635","1","Hard disk 2","SCSI(1:1)","physicalMode","192.168.85.131"
"test02","naa.60000970000495700176533030463636","2","Hard disk 3","SCSI(1:2)","physicalMode","192.168.85.131"
"test03","naa.60000970000495700176533030463637","1","Hard disk 2","SCSI(2:1)","physicalMode","192.168.85.132"
"test03","naa.60000970000495700176533030463638","2","Hard disk 3","SCSI(2:2)","physicalMode","192.168.85.132"
add-rdm.ps1
Import-Csv -Path report.csv -UseCulture | %{
$esxName = $_.VMHost
$vmNames = $_.VM
$lunNAA = $_.Canonical
$lunTab = @{}
Get-VMHost -Name $esxName | Get-ScsiLun -LunType disk |
where{$lunNAA -contains $_.CanonicalName} | %{ $lunTab.Add($_.CanonicalName,$_.ConsoleDeviceName)
}
$hd = @()
$first = $true
foreach($vm in (Get-VM -Name $vmNames)){ if($first){ foreach($lun in $lunNAA){ if($first){ $hd += New-HardDisk -VM $vm -DiskType RawPhysical -DeviceName $lunTab[$lun] } } $ctrl = New-ScsiController -HardDisk $hd -BusSharingMode Physical -Type VirtualLsiLogicSAS $first = $false } else{ $spec = New-Object VMware.Vim.VirtualMachineConfigSpec $spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec $spec.deviceChange[0].device += $ctrl.ExtensionData $spec.deviceChange[0].device.Key = -101 $spec.deviceChange[0].operation = 'add' $i = -102 $hd.GetEnumerator() | %{ $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec $dev.device += $_.ExtensionData $dev.device.Key = $i $dev.device.ControllerKey = -101 $dev.operation = "add" $spec.DeviceChange += $dev $i-- } $vm.ExtensionData.ReconfigVM($spec) }
}
}
sharedisk.csv
"VM","filepath","HDLabel","SCSIID","ControllerID","HDMode","VMHost"
"test02","[datastoreDC] test01/test_3.vmdk","0","Hard disk 3","SCSI(1:0)","1","physicalMode","192.168.85.130"
"test03","[datastoreDC] test01/test_3.vmdk","0","Hard disk 3","SCSI(2:0)","2","physicalMode","192.168.85.131"
"test12","[datastoreEC] test11/test_4.vmdk","0","Hard disk 3","SCSI(1:0)","1","physicalMode","192.168.85.130"
"test12","[datastoreEC] test11/test_5.vmdk","0","Hard disk 3","SCSI(2:0)","2","physicalMode","192.168.85.131"
"test13","[datastoreEC] test11/test_4.vmdk","0","Hard disk 3","SCSI(1:1)","1","physicalMode","192.168.85.130"
"test13","[datastoreEC] test11/test_5.vmdk","0","Hard disk 3","SCSI(2:1)","2","physicalMode","192.168.85.131"
add-exsting-rdm.ps1
Import-Csv "sharedisk.csv" -UseCulture | %{
$vms = $_.VM
$HD = $_.
$Diskpath = $_.filepath
$hd=$_.HDLabel
#SC=$_.ControllerID
$vm = Get-VM -Name $VMs
$ctrl1 = New-ScsiController -HardDisk $hd -BusSharingMode Physical -Type VirtualLsiLogicSAS
New-HardDisk -VM $vm -DiskPath $Diskpath -Controller $sc
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].device += $ctrl1.ExtensionData
$spec.deviceChange[0].device.Key = -101
$spec.deviceChange[0].operation = "add"
$spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[1].device += $hd1.ExtensionData
$spec.deviceChange[1].device.Key = -102
$spec.deviceChange[1].device.ControllerKey = -101
$spec.deviceChange[1].operation = "add"
$vm.ExtensionData.ReconfigVM($spec)
}