通过PowerCLI在MSCS VM的SCSI控制器上添加RDM

时间:2016-11-07 15:42:55

标签: powershell vsphere powercli raw-disk

我正在尝试引用以下链接以导入csv并使用数据在MSCS环境中附加RDM。 [Distributing RDMs across SCSI controllers when adding hard disks via PowerCLI

我已经获得了导出csv报告的所有有用信息,如下所示:

"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"

我无法将CSV导入RDM返回其VM,以及如何查找RDM VMDK文件的第一个VM,然后在MSCS中附加另一个VM。

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
    }
}

}

我很感激你的信息,提前谢谢。

0 个答案:

没有答案