In System Center Virtual Machine Manager 2012, you have the option to modify your Guest OS settings when deploying a new virtual machine. The settings you can modify are things like the product key, local administrator password, etc.
One other thing you can define, is that fact that the new virtual machine has to be joined to the domain. Very useful. But what if you also want to define the default Organizational Unit this machine has to be put in? Well, that can also be done using the Guest OS Profile.
The only thing is, that you can’t define this in the VMM Administrative Console. Below is a screenshot of one of my Guest OS Profile settings.
These are all the settings you can set through the console in regards of domain information. But if you use the CmdLets which come with the Administrative Console installation, you can define the default OU. To do this, start the “Virtual Machine Manager Command Shell” from the start menu (it’s in the VMM 2012 start menu folder). This will load the VMM PowerShell module.
Now to get the Guest OS Profile using PowerShell, you can use the following CmdLet:
Get-SCGuestOSProfile -Name "Win7-Sequencer"
This will output something like this:
FullName : OrgName : ComputerName : * Admin : AdminPasswordRunAsAccount : AdminPasswordHasValue : False ProductKeyHasValue : False GuiRunOnceCommands : {} JoinDomain : lab.local DomainAdmin : LAB\Administrator JoinDomainRunAsAccount : DomainAdminPasswordHasValue : True JoinWorkgroup : TimeZone : 110 MergeAnswerFile : False SysprepScript : OperatingSystem : 64-bit edition of Windows 7 ServerFeatures : {} AutoLogonCredential : AutoLogonCount : UnattendSettings : {} DomainJoinOrganizationalUnit : GrantedToList : {} UserRoleID : 75700cd5-893e-4f68-ada7-50ef4668acc6 UserRole : Administrator Owner : LAB\Administrator ObjectType : GuestOSProfile Accessibility : Public Name : Win7-Sequencing IsViewOnly : False Description : AddedTime : 22-5-2012 15:03:12 ModifiedTime : 22-5-2012 15:03:38 Enabled : True MostRecentTask : Change properties of operating system profile ServerConnection : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection ID : bd85e45c-959e-4754-9eb7-2b979785da8b MarkedForDeletion : False IsFullyCached : True
As you can see, one of the properties is “DomainJoinOrganizationalUnit”. This is the property that I’m talking about. Now, to set the OU value, use this code:
Get-SCGuestOSProfile -Name "Win7-Sequencing" | Set-SCGuestOSProfile -DomainJoinOrganizationalUnit "OU=Virtual,OU=Computers,OU=Lab,DC=lab,DC=local"
After executing this code, PowerShell will output the new configuration of your Guest OS Profile (note the UnattendSettings and DomainJoinOrganizationalUnit properties):
FullName : OrgName : ComputerName : * Admin : AdminPasswordRunAsAccount : AdminPasswordHasValue : False ProductKeyHasValue : False GuiRunOnceCommands : {} JoinDomain : lab.local DomainAdmin : LAB\Administrator JoinDomainRunAsAccount : DomainAdminPasswordHasValue : True JoinWorkgroup : TimeZone : 110 MergeAnswerFile : True SysprepScript : OperatingSystem : 64-bit edition of Windows 7 ServerFeatures : {} AutoLogonCredential : AutoLogonCount : UnattendSettings : {[3/Microsoft-Windows-UnattendedJoin/Identification/MachineObjectOU, OU=Virtual,OU=Compu ters,OU=Lab,DC=lab,DC=local]} DomainJoinOrganizationalUnit : OU=Virtual,OU=Computers,OU=Lab,DC=lab,DC=local GrantedToList : {} UserRoleID : 75700cd5-893e-4f68-ada7-50ef4668acc6 UserRole : Administrator Owner : LAB\Administrator ObjectType : GuestOSProfile Accessibility : Public Name : Win7-Sequencing IsViewOnly : False Description : AddedTime : 22-5-2012 15:03:12 ModifiedTime : 22-5-2012 15:47:40 Enabled : True MostRecentTask : Change properties of operating system profile ServerConnection : Microsoft.SystemCenter.VirtualMachineManager.Remoting.ServerConnection ID : bd85e45c-959e-4754-9eb7-2b979785da8b MarkedForDeletion : False IsFullyCached : True
If you now use this Guest OS Profile when deploying a virtual machine from a template, your machine will be joined to the domain and the machine account will be put in the given OU.
I’ve created a little PowerShell script which you can use to modify your Guest OS Profile and set this OU property. You can get it from the Microsoft Technet Gallery:
http://gallery.technet.microsoft.com/Set-default-OU-for-Guest-4224c9f4
Hope this post was useful for you.
Great post! I was looking to do the same thing and found a solution using an unattend.xml file. Keep up the great work!
Very useful. It taught me to start using SCVMM PowerShell instead of relying on the GUI.