MDT 2013 Update 2: Adding Domain OU’s with Friendly Names

Adding computers to the domain is easy if you want them to all end up in the (default) computers OU, or pre-populate the computer account in active directory.

For those of us that like to choose the computer OU on the fly when imaging, entering the OU manually is very tiring and mistakes are often made; at least for me.

To make it easier on the eyes, friendly names are the preferred way.

To make this happen, you will need to modify an INI file and create an XML file.  To speed up this process, I have provided the powershell code to make it happen.

Manual Steps to Make the Change:

1) Start notepad as an administrator.
2) Open file <DeployRoot>\Scripts\DeployWiz_ComputerName.vbs  (e.g. C:\DeploymentShare by default)
3) Locate the following and make the changes indicated.

Original: Function AddItemToMachineObjectOUOpt(item)

Changed:  Function AddItemToMachineObjectOUOpt(item,value)
Original: oOption.Value = item

Changed:  oOption.Value = value
Original: AddItemToMachineObjectOUOpt oItem.text

Changed:  AddItemToMachineObjectOUOpt oItem.text, oItem.Attributes.getNamedItem("value").value

PowerShell Commands to Make the Changes:

$DomainOUListFile = @"
<?xml version="1.0" encoding="utf-8"?>

<DomainOUs>

	<DomainOU value="OU=Computers,DC=contoso,DC=corp,DC=com">
		Default Computer OU
	</DomainOU>

	<DomainOU value="">
		--[ Site 1 Name ]--
	</DomainOU>

	<DomainOU value="OU=Site 1,OU=Computers,DC=contoso,DC=corp,DC=com">
		Site 1 Computers
	</DomainOU>

	<DomainOU value="">
		--[ Site 2 Name ]--
	</DomainOU>

	<DomainOU value="OU=Site 2,OU=Computers,DC=contoso,DC=corp,DC=com">
		Site 2 Computers
	</DomainOU>

	<DomainOU value="">
		--[ Site 3 Name ]--
	</DomainOU>

	<DomainOU value="OU=Site 3,OU=Computers,DC=contoso,DC=corp,DC=com">
		Site 3 Computers
	</DomainOU>


</DomainOUs>

"@

$FolderPath = "C:\Deploymentshare"
Remove-Item -Path "$FolderPath\Control\DomainOUList.xml" -Force
New-Item -Path "$FolderPath\Control\DomainOUList.xml" -ItemType File -Value $DomainOUListFile


$DWCNFile = "$FolderPath\Scripts\DeployWiz_ComputerName.vbs"
(Get-Content $DWCNFile) | Foreach-Object {
	$_ -replace 'Function AddItemToMachineObjectOUOpt\(item\)', 'Function AddItemToMachineObjectOUOpt(item,value)' `
	   -replace 'oOption.Value = item', 'oOption.Value = value' `
	   -replace 'AddItemToMachineObjectOUOpt oItem.text', 'AddItemToMachineObjectOUOpt oItem.text, oItem.Attributes.getNamedItem("value").value'
	} | Set-Content $DWCNFile




Loading

Posted in MDT