MMS2012 – SC 2012 VMM: PowerShell Is Your Friend, And Here’s Why

Speakers: Hector Linares, Senior Program Manager and Susan Hill, Senior Technical Writer, MSFT

Went from 162 cmdlets in VMM 2008 R2 to 438 in VMM 2012.  They maintained backwards compatibility through aliases.  The cmdlets got renamed so they don’t conflict with the new Windows Server 2012 Hyper-V cmdlets.

POSH is the driving force for the UI.  Cmdlets are executed as jobs in VMM so there’s an audit trail.  Other partners, e.g. TFS or XenDesktop, integrates with VMM cmdlets for deployment.

Overview of VMM 2012 system

  • Infrastructure: HA VMM Server, PowerShell, Upgrade, Custom Properties
  • Fabric: Server lifecycle management, multiple hypervisors, network management, storage management, dynamic optimisation.
  • Clouds: An abstraction of fabrics.  Application ower usage, capacity and capability, delegation and quota.
  • Services: Service templates, application deployment, customer command execution, image-based servicing.

Cmdlet groups: 46 nouns

  • get-command –module VirtualMachinemanager –commandtype cmdlet
  • get-scvirtualmachine
  • Now you run read-SCvirtualmachine to do a refresh
  • Repair-scvirtualmachine wil do the repair action.
  • Stop-scvirtualmachine takes more parameters, e.g. stop (cold), save state, or clean shutdown
  • Register-sCVMHost to register a bare metal host.
  • Restart-SCVMHost to reboot a host.
  • Test-SCVMHostCluster to run a cluster validation.

Domain Join for VM

You can use –DomainJoinOrganizationalUnit “ou=, dc=” to set where a new VM joins in a domain.

-AutolongCredential to  set autologon account and –AutoLogonCount to say how many times that will run.

These must be set at the same time.  You can clean up with disableautologon.


Looks like we can use this to customise an unattend.xml for Specialize (3) and OOBE (6) passes.  Use Add)key,value) to add settings.

  • $unattend.add
  • $unattend.remove

Your settings will override settings in GuestOSProfile or VMTemplate.  You have to commit the settings with set-scvmtemplate (I think – quick slides) to use them.


In the demo, he wants to override a template.  He gets the template.  Now he creates a new temporary template.  He sets the OU for it to join to.  He creates runas account as the account he’ll use for building the VM.  He uses that for autologon.  He get’s the unattend object.  No he adds a bunch of overrides to the template using $unattend.add().  set-scvmtemplate – vmtemplate $template –UnanntedSettings $unattend) | Out-Null commits the overrides.  They create a $vmconfig using new-scmconfiguration –vmtemplate $template –Name ($vmNamePrefix + @_config@)) | fl Name. 

VMM still doesn’t have the ability to create differencing disks so you have to use WMI to do it instead.  Apparently this has been blogged. 

He sets the disk name and location.  This can be done on a per disk basis.  In this cmdlet he’s told it to use an existing VHD he just created using WMI. 

Virtual Machine Configuration

You can create a VM config so you can deploy very specific VM configs, different from the defaults.  $VHD to get-scvirtualharddisk from the library.  Then set$storageclass viariable with get-scstorageclassification.  Now $ComputeTier with get-sccomputertier.  Then $VMconfig with new-scvmconfiguration and the $computertier variable.  $vhdconfig and get-scvirtualharddiskconfiguration and $vmconfig.  setscvirtualharddiskconfiguration and $vhdconfig and $vhd and $storageclass. 

Now $virtualnetworkadatperconfig = get-scvirtualnetworkadapterconfiguration.  Setscvirtunetworkadapterconfiguration with $virtualnetadapterconfiguration.  And then more stuff.  Download the slide deck when it comes out in a few days.

Basically you build up a VM config and then you create a VM from that config.

There is a script on the net that will automatically sign the scripts in your VMM library.  It was written for 2008 R2.

We’re shown a demo where a script checks for expired (by date) VMs and stores them in the VMM library.

Hyper-V Data Exchange

Can read and set the KVPs in the VM.  Can read data from a VM without using the network via read.  Can pass in string values to a VM regardless of power state with Set.  A Key is a registry VALUE create to store DATA.  The value is the DATA.  And a KVPMAP is a hash table is one ore more VALUEs or DATA.

Cool demo where Hector writes to the registry of the VM in different power states (on, off, paused, save state).


Jobs submitted to VMM using –RunAsynchronously from one or more runspaces.  Hundreds of parallel jobs.  Typically used in the morning bootstorm in VDI.

VMM 2012 has a concept of threadpools.  By default it handles 25 threads per core in the VMM server with a max of 150 (requires a monster VMM server).  High number of context switches can slow performance of the VMM server.  The WCF timeout is configurable (default of 120 seconds).  Monitor the performance of jobs if you increase threadpools.

If you run asynchronously then query the job object for status.  For higher throughput, use multiple threads with multiple runspaces.

Make sure you tune the VMM refreshers in VDI, and also in very large static environments.  4000 VMs doing a light refresh every 2 minutes and a ful refresh every 30 minutes will hammer the VMM server. 


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.