Category Archives: vCenter

Match Windows Drive Letter to VM Disk with PowerCLI

 

Matching OS Drive Letters to VM Disks is definitely something each VMware admin has wanted at some point or another. Unfortunately, it is not the easiest of tasks. Using a suggestion I found in one of the forum posts that the solution might be a combination of two different scripts referenced here and here, I decided to try it out.

After combining and editing the scripts a bit it seems to work really well for me, although I am sure individual results may vary. Anyway here is the script…

 


$DiskInfo= @()
$Vm = "vmname"

$i=0


$disks=Get-VM $vm| Get-HardDisk -DiskType "RawPhysical","RawVirtual"
$logtopart=Get-WmiObject -Class Win32_LogicalDiskToPartition -computername $VM 
$disktopart=Get-WmiObject Win32_DiskDriveToDiskPartition -computername $VM 
$logical=get-wmiobject win32_logicaldisk -computername $Vm
$volume=get-wmiobject win32_volume -computername $Vm
$partition=get-wmiobject win32_diskpartition -computername $Vm
if (($VmView = Get-View -ViewType VirtualMachine -Filter @{"Name" = $Vm})) {
    $WinDisks = Get-WmiObject -Class Win32_DiskDrive -ComputerName $VmView.Name
    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, NAA,drive, volumename
            $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
            $virtualdisk.naa=$disks|? {$_.name -like $VirtualDiskDevice.DeviceInfo.Label}|select -expand scsicanonicalname




            # Match disks based on SCSI ID
            $DiskMatch = $WinDisks | ?{($_.SCSIPort -2 ) -eq $VirtualSCSIController.BusNumber -and $_.SCSITargetID -eq $VirtualDiskDevice.UnitNumber}
            if ($DiskMatch){
                $VirtualDisk.WindowsDisk = "Disk $($DiskMatch.Index)"
            $i++
            }
            else {Write-Host "No matching Windows disk found for SCSI id $($VirtualDisk.SCSI_Id)"}
            

            $matchdisktopar=$disktopart|Where {$_.Antecedent -eq $diskmatch.__Path}
             $matchlogtopart=$logtopart| Where {$_.Antecedent -eq $matchdisktopar.Dependent}
             $logicalmatch=$logical| where {$_.path.path -eq $matchlogtopart.dependent}
             $VirtualDisk.volumename=$logicalmatch.volumename
             $virtualdisk.drive=$logicalmatch.deviceid


             $DiskInfo += $VirtualDisk
        }
    }
    $DiskInfo | Out-GridView
}
else {Write-Host "VM $Vm Not Found"}

A couple things to note, you obviously need WMI open on the target windows machine, and the permissions to perform WMI calls against said machine.

Here is how it looks once completed.

 

 

The NAA is blank because none of these disks are RDMs, otherwise, NAA would be populated as well. Also for some reason it is not grabbing the C drive….might have to look at that.

 

Regardless it is pretty handy to have in the back pocket when you need it.

 

Let me know what you think

Using PowerCLI to Automate SRM Post Power On Commands

Long Title… But first things first. http://www.benmeadowcroft.com/projects/srm-cmdlets-for-powercli/ Ben Meadowcroft created several cmdlets and even a module using the SRM API. Having spent a good deal of time in the SRM API myself, let me tell you….IT IS A MESS. Long story short Ben, spent a lot of time creating this really helpful module, and you… Continue Reading

Installing vSphere 6

Installing vSphere 6

Let’s get started installing vCenter. It is never a bad idea to know what screens and information you will need before you get get there! Already this looks SIGNIFICANTLY more streamlined than the vSphere 5.5 installations with SSO, Inventory Service, etc etc etc Next next next! I went with Embedded Deployment, this means everything necessary… Continue Reading

Lower HIGH Java RAM Usage on vCenter Server

This is especially useful for SMB who don’t have large environments, and can’t throw resources at a vCenter Server This is what one of my vCenter Servers looked like recently To give some insight, this is a vCenter that manages around 3 hosts and 50 VMs. I quickly found a KB about java memory usage… Continue Reading

VMware vCenter MDMP Files

My vCenter Server was acting up and throwing a bunch of random errors. When I started investigating it appeared that the C drive was out of space. Completely Out. Yeah, I guess I haven’t been a very good administrator…. So after a few minutes of some quick cleaning and getting everything up and running I… Continue Reading

VMHost Heartbleed Fix for ESXi 5.5

If you don’t know about Heartbleed yet…Well I don’t know what to say… I guess check this out. http://heartbleed.com/ Unfortunately, ESXi is susceptible to this The full kb is here from VMware  http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2076665 Fortunately it can be patched with everyone’s favorite patch tool VMware Update Manager Now that I have been able to scan my… Continue Reading

VMware Update Manager Errors On Scan

While working on getting my hosts properly patched, I found I couldn’t even do a scan on them. Alright so next I took a look at the esxupdate log on the host. Both of these correspond to a VMware kb found Here The cause as listed in the KB “This error occurs when two VIBs… Continue Reading

Clearing Stubborn Hardware Status Errors

Sometimes those hardware status Errors/Warnings do not want to clear even after you have fixed the issue In my case, I had a drive failed in a ESXi host that had 2 drives in Raid 1. No Biggie, just replace the drive. After replacing the drive and confirming everything was in the green(via an IBM… Continue Reading