Hi All,
Can anyone here please assist me with the powershell script if possible to list the VM information like the following format or in CSV format is OK:
SCSI (0:0) VM Hard Disk 1 [R5D23] PRODFSCLUS01-VM/PRODFSCLUS01-VM.vmdk - Windows C: drive - 60 GB
SCSI (1:1) VM Hard Disk 2 [NAS-D76] PRODFSCLUS01-VM/PRODFSCLUS01-VM.vmdk - Windows Q: drive - 1 GB
SCSI (1:2) VM Hard Disk 3 [NAS-D23] PRODFSCLUS01-VM/PRODFSCLUS01-VM.vmdk - Windows G: drive - 1.77 TB
SCSI (1:3) VM Hard Disk 4 [R5D52] PRODFSCLUS01-VM/PRODFSCLUS01-VM.vmdk - Windows H: drive - 1.77 GB
SCSI (1:4) VM Hard Disk 5 [NAS-D19] PRODFSCLUS01-VM/PRODFSCLUS01-VM.vmdk - Windows T: drive - 60 GB
Thanks in advance.
If your VMware Tools are on the correct version, you can use the Get-VMGuestDisk cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have PowerCLI 12.0.1 installed, but we are still on vSphere 6.7, so we get this message:
It's been a couple of months and I am just getting back to this after getting our vCenters upgraded to 7.0. The command Get-VMGuestDisk is useful, but it does not appear to give the details of SCSI device or the VMDK's location in storage. It does contain a reference back to the VM object (VMGuest), but no clear way to like the GuestDisks to VMDKs, like a UID or objectID.
Have a look at New Release – PowerCLI 12, that explains how the link works.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for the reply, but it is still not working for me. Here is what I am working with:
PowerCLI 12.2
VMware Tools 11.2.97 installed on the target VM
vCenter 7.0.1
when I run the commands, this is what I get:
The error is clear, that VM doesn't provide the Guest DIsk mapping.
That would mean one of the requirements for this to work is not met.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you for the RTFM response, and I am mostly kidding. I thought I had provided all the required info to show that I had already double-checked the prerequisites listed here. I did notice that the VM was still on an old version of virtual hardware, and upgraded it to v15. However, I am still getting the same results. I even checked the Developer Documentation on the command and found nothing additional. Any suggestions?
There are some more requirements, not all of them documented in the PowerCLI Reference.
You might want to have a look at Cody's post What’s New in vSphere 7.0 Storage Part III: GuestInfo VirtualDiskMapping Linux, PowerCLI support
He lists his conclusion at the end of the post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Crap - my ESXi hosts are still on 6.7 and ESXi 7.0 is required. I didn't find that specific piece of info until I checked out Part II of Cody's post.
I will move forward with my script that will work in both 6.7 and 7.0. It is not perfect because I am depending on the drives returned by Get-HardDrive to have been added in the same order they appear in the Get-VMGuestDisk. I will need to add some additional logic to verify.
Thanks again!
How can I make this disk association to Linux server partitions (Red Hat Enterprise)
#This script based on his, also associates de drive letter:
$computer = "VMNAME"
$VMView = Get-View -ViewType VirtualMachine -Filter @{'Name' = "^$($computer)$"}
# Obtén información sobre discos y particiones
$ServerDiskToVolume = @(
Get-WmiObject -Class Win32_DiskDrive -ComputerName $computer | foreach {
$Dsk = $_
$query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_DiskPartition"
Get-WmiObject -Query $query -ComputerName $computer | foreach {
$query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_LogicalDisk"
Get-WmiObject -Query $query -ComputerName $computer | Select DeviceID,
VolumeName,
@{ label = "SCSITarget"; expression = {$dsk.SCSITargetId} },
@{ label = "SCSIBus"; expression = {$dsk.SCSIBus} }
}
}
)
# Now loop through all the SCSI controllers on the VM and find those that match the Controller and Target
$VMDisks = 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})) {
# Build a custom object to hold this.
$VMSummary = [pscustomobject]@{
VM = $VM.Name
HostName = $VMView.Guest.HostName
PowerState = $VM.PowerState
DiskFile = $VirtualDiskDevice.Backing.FileName
DiskName = $VirtualDiskDevice.DeviceInfo.Label
DiskSize = $VirtualDiskDevice.CapacityInKB * 1KB
SCSIController = $VirtualSCSIController.BusNumber
SCSITarget = $VirtualDiskDevice.UnitNumber
DeviceID = $null
}
# Match up this VM to a logical disk
$MatchingDisk = $ServerDiskToVolume | Where { $_.SCSITarget -eq $VMSummary.SCSITarget -and $_.SCSIBus -eq $VMSummary.SCSIController }
if ($MatchingDisk) {
$VMSummary.DeviceID = $MatchingDisk.DeviceID
} else {
$VMSummary.DeviceID = "Offline"
}
$VMSummary
}
}
# Output the combined information as an autosized table
$VMDisks | Format-Table -AutoSize