我想将Windows操作系统中的驱动器与vCenter *.vmdk
匹配。
这是我需要的信息的link。我发现无法使用powershell(来自磁盘的信息)获取“位置192(总线编号0,目标ID 0,LUN 0)”。从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
< - Replace - 1 with - 2.
并在{$_.DeviceInfo.Label -match "SCSI-Controller"}))
之间在SCSI控制器之间加上“ - ”。
为什么我必须从SCSIPort中减去2?
答案 0 :(得分:0)
以下脚本将本地Windows磁盘与vmWare磁盘匹配。
masterauth