Using PowerShell to Look at a VM Configuration
I was recently asked to provide a PowerShell sample that would let you see everything inside a virtual machine configuration file - without having to import the virtual machine in question. Here is what I put together:
Function Expand-VMConfig ($VMConfig) {
$tempVM = (Compare-VM -Copy -Path $VMConfig -GenerateNewID).VM
write-host "VM Configuration Data"
write-host "====================="
$tempVM | Select *
write-host "VM Network Adapters"
write-host "====================="
$tempVM.NetworkAdapters
write-host "VM Hard Drives"
write-host "====================="
$tempVM.HardDrives
write-host "VM DVD Drives"
write-host "====================="
$tempVM.DVDDrives
write-host "VM Floppy Drive"
write-host "====================="
$tempVM.FloppyDrive
write-host "VM Fibre Channel"
write-host "====================="
$tempVM.FibreChannelHostBusAdapters
write-host "VM COM1"
write-host "====================="
$tempVM.ComPort1
write-host "VM COM2"
write-host "====================="
$tempVM.ComPort2}
If you run this code on a PowerShell prompt you can now use "Expand-VMConfig". It takes a single parameter of a virtual machine configuration file - and displays you everything you could possibly want to know about it.
Cheers,
Ben