1
我想將windows操作系統中的驅動器與vCenter *.vmdk
相匹配。Powershell將虛擬中心中的虛擬硬盤與其磁盤標籤匹配
這是我需要的信息link。我發現沒有辦法獲得「位置192(總線號0,目標ID 0,LUN 0)」與powershell(從磁盤信息)。從WMI我沒有得到這個信息...
有人可以幫忙嗎?
修改後的腳本:
$Vm = "VMName"
if (($VmView = Get-View -ViewType VirtualMachine -Filter @{"Name" = $Vm})) {
$Out = Get-WmiObject -Class win32_diskdrive -Property Index, SCSIPort, SCSITargetId -ComputerName $Vm
#Invoke-VMScript "wmic path win32_diskdrive get Index, SCSIPort, SCSITargetId /format:csv" -vm $VM -scripttype "bat"
foreach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | where {$_.DeviceInfo.Label -match "SCSI-Controller"})) {
foreach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | where {$_.ControllerKey -eq $VirtualSCSIController.Key})) {
$VirtualDisk = "" | Select SCSIController, DiskName, SCSI_Id, DiskFile, DiskSize, WindowsDisk
$VirtualDisk.SCSIController = $VirtualSCSIController.DeviceInfo.Label
$VirtualDisk.DiskName = $VirtualDiskDevice.DeviceInfo.Label
$VirtualDisk.SCSI_Id = "$($VirtualSCSIController.BusNumber) : $($VirtualDiskDevice.UnitNumber)"
$VirtualDisk.DiskFile = $VirtualDiskDevice.Backing.FileName
$VirtualDisk.DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB/1GB
# Match disks based on SCSI ID
$DiskMatch = $Out | ?{($_.SCSIPort - 2) -eq $VirtualSCSIController.BusNumber -and $_.SCSITargetID -eq $VirtualDiskDevice.UnitNumber}
if ($DiskMatch){
$VirtualDisk.WindowsDisk = "Disk $($DiskMatch.Index)"
}
else {Write-Host "No matching Windows disk found for SCSI id $($VirtualDisk.SCSI_Id)"}
$DiskInfo += $VirtualDisk
}
}
$DiskInfo | Out-GridView
我不得不改變$DiskMatch = $Out | ?{($_.SCSIPort - 2) -eq
< - 更換 - 1 - 2
,把一個「 - 「之間的SCSI控制器{$_.DeviceInfo.Label -match "SCSI-Controller"}))
。 爲什麼我必須從SCSIPort中減去2?
有趣的閱讀:http://www.van-lieshout.com/2009/12/match-vm-and-windows-harddisks-using-powercli/ – 2014-10-07 11:48:24
謝謝你的URL。我看到了這個,但id不會在我的環境中工作。我修改了腳本,它工作。但我認爲有更好的解決方案? – Patrick 2014-10-07 13:15:27