I extracted info from my VCentre VCDBs because i am more comfortable using SQL than PowerCLI.
I have a list of servers, with a Disk Number, SCSI ID and Allocated Size.
SERVER0001 - DISK NUMBER 1 - SCSI1:0 - 100GB
I also have a list of servers, with Path and Sizes from the VPX_GUEST_DISK table.
SERVER0001 - C: - 100GB
I need to bridge the gap between a Disk Number OR SCSI ID - and a Windows Drive Letter, and cannot do it with disk size alone.
I found this script, which works for some of my servers, But the function only takes a single parameter at a time,
could someone please edit this - so that it will (a) accept a list of parameters, from CSV or Txt
and (b) Output the result to CSV.
##Script Below## - Thanks
Function Get-VMDiskMap {
[Cmdletbinding()]
param([Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][string]$VM)
begin {
}
process {
if ($VM) {
$VmView = Get-View -ViewType VirtualMachine -Filter @{"Name" = $VM}
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 VM,SCSIController, DiskName, SCSI_Id, DiskFile, DiskSize, WindowsDisks
$VirtualDisk.VM = $VM
$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
$LogicalDisks = @()
# Look up path for this disk using WMI.
$thisVirtualDisk = get-wmiobject -class "Win32_DiskDrive" -namespace "root\CIMV2" -computername $VM | where {$_.SCSIBus -eq $VirtualSCSIController.BusNumber -and $_.SCSITargetID -eq $VirtualDiskDevice.UnitNumber}
# Look up partition using WMI.
$Disk2Part = Get-WmiObject Win32_DiskDriveToDiskPartition -computername $VM | Where {$_.Antecedent -eq $thisVirtualDisk.__Path}
foreach ($thisPartition in $Disk2Part) {
#Look up logical drives for that partition using WMI.
$Part2Log = Get-WmiObject -Class Win32_LogicalDiskToPartition -computername $VM | Where {$_.Antecedent -eq $thisPartition.Dependent}
foreach ($thisLogical in $Part2Log) {
if ($thisLogical.Dependent -match "[A-Z]:") {
$LogicalDisks += $matches[0]
}
}
}
$VirtualDisk.WindowsDisks = $LogicalDisks
Write-Output $VirtualDisk
}
}
}
}
end {
}
}