Adding the RDMs across SCSI controllers for MSCS VMs via PowerCLI

738 Views Asked by At

I’m trying to refer below link for importing the csv and using the data to attach the RDM in MSCS environment. [Distributing RDMs across SCSI controllers when adding hard disks via PowerCLI

I have got the all useful information to export the csv report as the following:

"VM","Canonical","UnitNr","HDLabel","SCSIID","HDMode","VMHost"
"test01","naa.600009700......","1","Hard disk 2","SCSI(1:1)","physicalMode","192.168.85.130"
"test01","naa.600009700......","2","Hard disk 3","SCSI(1:2)","physicalMode","192.168.85.130"
"test02","naa.600009700......","1","Hard disk 2","SCSI(1:1)","physicalMode","192.168.85.131"
"test02","naa.600009700......","2","Hard disk 3","SCSI(1:2)","physicalMode","192.168.85.131"
"test03","naa.600009700......","1","Hard disk 2","SCSI(2:1)","physicalMode","192.168.85.132"
"test03","naa.600009700......","2","Hard disk 3","SCSI(2:2)","physicalMode","192.168.85.132"

I’m having difficulty importing the CSV to the RDM go back to its VM, and how find out the first VM of RDM VMDK file then attach another VMs in MSCS.

Import-Csv -Path report.csv -UseCulture | %{
$consdevnam = "/vmfs/devices/disks/"
$devicePointer = 0
$global:my_VM_hosts=$_.VMHost
$naa_ids=$_.Canonical
$localVM=$_.VM
foreach ($global:Vmhost in $global:my_VM_hosts){
    foreach ($localVM in $global:my_VMs){
        $global:scsi_ctrl = $null
        $global:scsi_ctrl = @()
        $flag = 0
        for($i=$devicePointer;$i -lt $devicePointer+$devicesPerVM; $i++){
            if ($flag -eq 0 -or ($flag % 4) -eq 0){
                $disk = New-HardDisk -VM $localVM -DeviceName ($consdevnam + $naa_ids[$i]) -DiskType RawPhysical -WarningAction SilentlyContinue
            }
            if ($flag -ne 0 -and $flag -lt 4) {
                $disk = New-HardDisk -VM $localVM -DeviceName ($consdevnam + $naa_ids[$i]) -DiskType RawPhysical -WarningAction SilentlyContinue
                $global:scsi_ctrl += New-ScsiController -HardDisk $disk -BusSharingMode NoSharing -Type ParaVirtual -WarningAction SilentlyContinue
            }
            elseif ($flag -ne 0 -and ($flag % 4) -lt 4) {
                $f = ($flag % 4)
                if ($f -eq 1){
                    $disk = New-HardDisk -VM $localVM -DeviceName ($consdevnam + $naa_ids[$i]) -Controller ($global:scsi_ctrl[0]).name -DiskType RawPhysical –Confirm:$false -WarningAction SilentlyContinue
                }                                                                                                                                                              
                if ($f -eq 2){                                                                                                                                                 
                    $disk = New-HardDisk -VM $localVM -DeviceName ($consdevnam + $naa_ids[$i]) -Controller ($global:scsi_ctrl[1]).name -DiskType RawPhysical –Confirm:$false -WarningAction SilentlyContinue
                }                                                                                                                                                              
                if ($f -eq 3){                                                                                                                                                 
                    $disk = New-HardDisk -VM $localVM -DeviceName ($consdevnam + $naa_ids[$i]) -Controller ($global:scsi_ctrl[2]).name -DiskType RawPhysical –Confirm:$false -WarningAction SilentlyContinue
                }
            }
            $flag+=1
            write-host "Added $disk to $localVM"
        }
        $devicePointer = $devicePointer+$devicesPerVM
    }
}

}

I'd appreciate your information, thanks in advance.

0

There are 0 best solutions below