when using VMM and deploying templates you not always want to place them in the default OU computers
But instead you want the Template Server 2016 places in OU TP5 and Hyper-V server directly placed in the OU Hyper-v.
Default there is no Gui item in the VMM console to do this. Say on the domain join tab place this VM in the Hyper-V OU
Instead of this you need to fill in the Value in Powershell. and Make a custom OU field.
You can Add Custom Properties as you like.
But first we are creating a Custom Guest OS profile this profile is the basis for the new build template and the Custom OU Placement.
Now that the Custom OS profile is in place we can check it there is a domain OU field
Get-SCGuestOSProfile
this shows us the field that we must fill in to get the right OU placement.
Get-SCGuestOSProfile |select Name
Get-SCGuestOSProfile -name "Guest OS 2016TP5"
Setting this in the OS profile
Get-SCGuestOSProfile -name "Guest OS 2016TP5" |Set-SCGuestOSProfile -DomainJoinOrganizationalUnit "OU=SCVMM16,DC=MVP,DC=local"
Now when I create a new template with this OS profile the VM is place in the SCVMM16 OU but it is not anywhere visible in the GUI.
and what if I have already build templates how to place them in Custom OU.
Yes you can do this. First I select all the templates to pick the right one
Get-SCVMTemplate |select name
$template = Get-SCVMTemplate | where {$_.Name -eq "ws2016G2"}
$template |select name
As I made the OU a variable :
$ou = "OU=SCVMM16,DC=MVP,DC=local"
Set-SCVMTemplate -VMTemplate $template -DomainJoinOrganizationalUnit $ou
So now the Template has a custom OU also.
But still there is no GUI property to show this. therefore go to the Template and create a Custom Property
go to the Manage custom Properties
Select Virtual Machine Template Properties give it a name “ custom OU “ and assign this to the template
Now that tis is assigned we can enable this in the GUI
But before we get any value in this field we need match this with the PowerShell Value DomainJoinOrganizationalUnit
Get-SCVMTemplate | %{ Set-SCCustomPropertyValue -InputObject $_ -CustomProperty $(Get-SCCustomProperty -Name "Custom OU") -Value $_.DomainJoinOrganizationalUnit }
As you can see there is an error this is because one template has no value.
Now With new deployments the VM’s will be places in the Custom OU
Follow Me on Twitter @ClusterMVP
Follow My blog https://robertsmit.wordpress.com
Linkedin Profile Http://nl.linkedin.com/in/robertsmit
Google Me : https://www.google.nl
Bing Me : http://tinyurl.com/j6ny39w
Thank you for this! However is it possible to allow it to use a variable? This seems to statically set it once but what if you wanted to change that value when actually deploying a VM template?
when you deploy the VM with powershell then you must set the OU first before the deployment and you can do this in a variable but it’s not that flexible but how many OU’s are use for placement the deployed template in powershell is easy and fast.