I’ve been having a fun time trying to get System Center Virtual Machine Manager 2012 SP1 beta to do things. It’s been even more fun when I’ve been trying via the delightful PowerShell – I want to get to a point where I can build/re-build servers quickly and easily.
My most recent conquest has been to get it to make a newly created virtual machine log on at the console at the end of the creation process.
I’m deploying Windows Server 2012 VMs, and have been able to get them to join to my active directory, that was relatively easy. Getting them to log on required some extra fiddling that I wasn’t expecting.
According to the documentation, which is sparse at best (even for the older and not beta non-SP1 VMM 2012) you just use the -AutoLogonCredential and specify a SCVMM RunAs account. What you actually have to specify is an object that contains a RunAs account. If you’ve been getting the VM to join an active directory then this is fairly easy to work out as it’s the same mechanism used to specify the -DomainJoinCredential. You set up a RunAs account via SCVMM which contains the username, password and domain, then just specify the name of this account (which is not necessarily the Active Directory SamAccountName – depends what name you gave the RunAs account when setting it up). This is quite nice as it means you don’t need to specify passwords in the script. e.g. to set up the credential object you use :
$DomainJoinCredential = Get-SCRunAsAccount -Name <your runas account>
In my case I wanted the server to log on as the same user I was using to join the server to AD, should have been simply a case of adding:
-AutoLogonCredential $DomainJoinCredential -AutoLogonCount 100
to the end of my New-SCVMTemplate command line.
Fail. The VM tries to log on but gives the following on screen:
Other user The user name or password is incorrect. Try again. [OK]
The VM is still joined to AD though, using the same credential object, so I know that the username and password is definately correct. It’s clearly not being passed to the VM’s OS properly. To fix this I changed my script a little and made a new code block to add all the autologon stuff in one place. It seems as though the critical bit that’s missing is the domain name. I now have the following code to modify the template I’ll use to create the virtual machine from:
Write-Host "Add autologon credential..." Set-SCVMTemplate -VMTemplate $Template -AutoLogonCredential $DomainJoinCredential -AutoLogonCount 100 | Out-Null $Unattend = $Template.UnattendSettings $Unattend.Add("6/Microsoft-Windows-Shell-Setup/Autologon/Domain","rcmtech") Set-SCVMTemplate -VMTemplate $Template -UnattendSettings $Unattend | Out-Null
The 6 on the $Unattend.Add line places the command into the oobesystem section of the unattend script.
I’ve previously created the temporary template using New-SCVMTemplate, then retrieved it into $Template by using:
$Template = Get-SCVMTemplate -Name <temporary template name>