Wednesday, May 8, 2013

VMM VM Template - AutoLogonCount and AutoLogonCredential for RunOnce

Recently I created a VM template in VMM 2012 SP1 for a customer. A number customization scripts were created and added to RunOnce. The customer wanted the VM template to automatically logon with the local Admin account so all the RunOnce scripts would run automatically.

This is a pretty standard request and when configuring any unattend Windows install this is generally achieved by modifying the unnattend.xml file. However in VMM the Set-SCVMTemplate PowerShell cmdlet can be leveraged to configure this setting.

The 'Get-SCVMTemplate' cmdlet will show the current AutoLogon configuration. The AutoLogonCount and AutoLogonCredentialproperties must both be configured to achieve the Auto Logon functionality:

Get-SCVMTemplate -Name "VM Template Name"

When using AutoLogon in your VM Template it is also important to have a VMM 'Run As' account configured that has the local Admin credentials stored. Once the local Admin 'Run As' account is created, add it to the VM Template OS Properties for the local admin account.

The following PowerShell cmdlets can be used to configure AutoLogonCount and AutoLogonCredential properties:

#Get Template by name
($template = Get-SCVMtemplate | where {$_.Name -eq "VM Template Name"}) | fl Name, OperatingSystem, VirtualizationPlatform

#Get local admin account
($raa = Get-SCRunAsAccount -Name "VM Local Admin Run As") | fl Name, Username, Domain

#Set auto logon
(Set-SCVMTemplate -VMTemplate $template -AutoLogonCredential $raa -AutoLogonCount 1) | fl Name, AutoLogonCredential, AutoLogonCount

By using Run As account for the local admin account for the OS Properties and the AutoLogonCredential this allows the local admin account to be changed without needing to rerun the above PowerShell scripts.

Happy Templating!


  1. Have you ever got a chance to try this with "Set-SCGuestOSProfile -AutoLogonCount"

    For me, I want to use it here so I can use a single template with multiple profiles, the only problem is the count never changes. Perhaps you can shed some insight?

  2. Hi Dean
    I just tested the above set of commands and replaced with Set-SCGuestOSProfile.
    I have provisioned a VM from a template and it seems to work.

  3. It's working but it's not usable.

    After 1 minute of the login, SCVMM shutdown the machine before all scripts\installations in GUIRunonce finished running. very limited usage

    MS is #1 of not thinking things thru

  4. what an awesome solution and worked first time around.
    is there anyway around the legal banner that pops before the auto login starts? at this point it's holding the auto login, because somebody has to click Ok in order for it to start.