Powershell – Systems Center Virtual Machine Manager–Identify Properties of Virtual Machines

powershell

Here’s your challenge.  Sometimes, no matter what you do, mistakes get made.   People create virtual Machines with the wrong Network Adapter time; Machines don’t migrate because of Server type mismatches.   Computers may not Autostart, simply because somebody forgot to enable the option.

That’s right.  Problems will Happen.   But with the Powershell Cmdlets in Systems Center Virtual Machine Manager 2008R2, this is less of a issue.   Because often if we have a list of things we can easily identify the problem and determine how to best resolve it.

Need to identify which machines ARE NOT starting up Automatically ?  Within SCVMM just execute this line to get a list of Machines to work with.

$VMLIST=GET-VM –VMMSERVER NAMEOFSCVMMSERVER

Now you have a complete list of your Hyper-V Machines managed by SCVMM.   Once you have the list, there is a series of properties available with GET-MEMBER.

$VMLIST | GET-MEMBER

You can now pull up the “Start Action” on all your Virtual Machines (and the stop) with this simple line

$VMLIST | Format-Table Name,Startaction,Stopaction –autosize

You can even filter this list down to show only the machines that aren’t starting automatically.

$VMLIST | Where { $-.StartAction –eq ‘Never AutoTurnOnVM’ } | Format-Table Name,StartAction,StopAction –autosize

Now do you have some Hyper-V servers with newer processors and some with older?   When migrating you can go forward in technology.  Going back is tricky unless you TELL the Virtual machine it can.

To identify those machines that can’t step back you need to check for the LimitCPUForMigration

$VMLIST | Where { $-.LimitCPUForMigration –eq $FALSE } | Format-table Name

Now if for any reason you’re unsure if your Virtual Machines have their Virtual Machine Additions, you can run a simply one liner again.

$VMLIST | format-table Name,HasVMAdditions

Now here’s a useful function to show you all the Computers in the Hyper-V environment that are still running with Legacy Network Adapters.

$VMLIST=GET-VM -VMMSERVER NAMEOFSCVMMSERVER
Foreach ($Machine in $AllVM )
    {
    $Adapterlist=$Machine.VirtualNetworkAdapters
    Foreach ($Adapter in $Adapterlist)
        {
        IF ($Adapter.VirtualNetworkAdapterType -ne ‘Synthetic’)
            {
            WRITE-HOST $Machine.Name,$Adapter.VirtualNetworkAdapterType,$Adapter.VMNetworkOptimizationsEnabled
            }
        }
    }

Why bother with this?  The more native your Hyper-V environment is, the fewer problems you can encounter.   Also when working with Systems Center Data Protection Manager and Hyper-V, you’ll want to make sure everything is as correct as possible to avoid that irritating “Backup Using Saved System State”,  a fallback backup method in DPM for Hyper-V Child Partitions.

All done with Powershell and a few minutes of typing.

Remember, the Power of Shell is in YOU
Sean
The Energized Tech

Leave a Reply