Freigeben über


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

Comments

  • Anonymous
    April 10, 2015
    Thanks for the script Ben.

  • Anonymous
    April 10, 2015
    Thanks Ben, The function works perfect for .XML config, what about for the new binary format in vNext .VMCX? Cheers, /Charbel

  • Anonymous
    April 12, 2015
    Charbel - Yes!  This will work with the new .VMCX files just as well. Cheers, Ben

  • Anonymous
    September 10, 2015
    is it possible to import a VM created on Windows 10 /2016 (so VMCX) on a Hyper-V 2012r2 ?

  • Anonymous
    October 07, 2015
    this doesn't work when the VM is running. It appears to be trying to copy the entire VM (as the copy switch would make one assume) Is there no way to open or query Hyper-V to list all VMCX contents without having to resort to imports and copies?

  • Anonymous
    October 13, 2015
    IMPORTANT ! - this only shows config for NEW VM which is going to be imported and not the config options from the VMXC file. Look at the VHD paths for example, they are relative to what new imported VM is going to have, and NOT what's in the VMXC file.