MDT 2012: Pre-populating The DomainOUs List
There’s a feature in MDT that displays a dropdown list of Domain OU’s in the Lite Touch deployment wizard.
Step 1: Let’s make a drop-down for the Organizational Unit text box during the “Computer Details” dialog box in the MDT deployment time
Step 2: Go into your MDT server and created a “DomainOUList.xml” file. Review the image for the format or view the video to see it 🙂
Step 3: Once you are completed with the xml file drop it into the scripts folder.
Step 4: Restart your MDT deployment and you should see the drop-down option now. NICE! 🙂
Ok guys! This script will prompt you for credentials and then generate a list of Organizational Units from Active Directory from the specified “SearchBase” that you specify, sort the results by CanonicalName (Example: “Domain.net/OU/OU/OU”) and then proceed to export each entry to “DomainOUList.xml” provided there were results from the query. This also makes use of the modification above and exports the DistinguishedName, and FriendlyName of each result. Have a blessed day folks! I hope this helps somebody!
Generates “DomainOUList.xml” file with each item formatted like the following
Domain.com \ Test \ Computers \ Workstations \ Branches \ Test
Output is also sent to “$Env:Windir\Temp\ScriptName.log”
This also requires the following modification within your to “DeployWiz_ComputerName.vbs” located in the “Scripts” folder of your Deployment Share for Microsoft Deployment Toolkit.
At roughly line 61 replace what is there with the following
Function AddItemToMachineObjectOUOpt(item)
AddItemToMachineObjectOUOptEx item, item
End Function
Function AddItemToMachineObjectOUOptEx(item,value)
Dim oOption
Set oOption = document.createElement(“OPTION”)
oOption.Value = value
oOption.Text = item
MachineObjectOUOptional.Add oOption
MachineObjectOUOptionalBtn.style.display = “inline”
End Function
At roughly line 158, replace what is there with the following
If MachineObjectOUOptionalBtn.style.display “inline” then
iRetVal = oUtility.FindFile(“DomainOUList.xml”, sFoundFile)
If iRetVal = SUCCESS Then
For Each oItem In oUtility.CreateXMLDOMObjectEx( sFoundFile ).selectNodes(“//DomainOUs/DomainOU”)
If oItem.Attributes.getNamedItem(“value”) Is Nothing Then
AddItemToMachineObjectOUOpt oItem.text
Else
AddItemToMachineObjectOUOptEx oItem.text, oItem.Attributes.getNamedItem(“value”).value
End If
Next
End If
End If
MDT will now display “FriendlyNames” for your organizational units during deployment!
Tested and working with MDT 2013 Update 1 with the latest Windows 10 ADK (10586)
If you prefer not to display friendlynames, skip the DeployWiz modification and comment out the line that uses friendlynames and uncomment the line that uses distinguishednames.
#######Powershell Script!
[CmdletBinding()]
Param
(
[String]$SearchBase = “OU=Place,OU=OrganizationalUnit,OU=Path,DC=Here,DC=com”,
[String]$ExportPath = “$ScriptDir\DomainOUList.xml”,
[String]$BackupPath = (Split-Path -Path $ExportPath -Parent) + “\DomainOUList_PreviousVersion.xml”
)
#Clear The Screen
Clear-Host
#Define Default Action Preferences
$DebugPreference = “Continue”
$ErrorActionPreference = “Continue”
$WarningPreference = “Continue”
#Define ASCII Characters
$Equals = [Char]61
$Space = [Char]32
$SingleQuote = [Char]39
$DoubleQuote = [Char]34
$NewLine = “`r”
$Tab = “`t”
#Set Working Directory
$ScriptDir = $MyInvocation.MyCommand.Definition | Split-Path -Parent
$ScriptName = [System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name)
$Temp = “$Env:Windir\Temp”
#Start logging script output
(Start-Transcript -Path “$Temp\$ScriptName.log”)
$NewLine
#Query WMI
$OSArchitecture = (Get-WmiObject -Class Win32_OperatingSystem -Property OSArchitecture | Select -ExpandProperty OSArchitecture).Replace(“-bit”, “”).Replace(“32″,”86″).Insert(0,”x”).ToUpper()
$OSCaption = (“{1} {2} {3}” -f (Get-WmiObject -Class Win32_OperatingSystem -Property Caption | Select -ExpandProperty Caption).Split(” “).Trim())
$OSVersion = [Decimal](“{0}.{1}” -f (Get-WmiObject -Class Win32_OperatingSystem -Property Version | Select -ExpandProperty Version).Split(“.”).Trim())
#Define Variables
$ExecutingUser_Domain = (Get-DnsClient | Where-Object {($_.ConnectionSpecificSuffix -ne “”) -and ($_.ConnectionSpecificSuffix -ne $Null)} | Select -First 1 -ExpandProperty ConnectionSpecificSuffix).Trim()
If (($ExecutingUser_Domain -eq “”) -or ($ExecutingUser_Domain -eq $Null)) {$ExecutingUser_Domain = $Env:UserDnsDomain.Trim()}
$ExecutingUser_UserName = $Env:UserName.Trim()
$ExecutingUser_FullName = (“{1} {0}” -f (Get-WmiObject -Class Win32_UserAccount -Filter “Name = ‘$ExecutingUser_UserName'” | Select -ExpandProperty FullName).Split(“,”).Trim())
If (($ExecutingUser_FullName -eq “”) -or ($ExecutingUser_FullName -eq $Null)) {$ExecutingUser_FullName = $ExecutingUser_UserName}
$Server = $ExecutingUser_Domain
#Create Secure Credential Object
$Credentials = (Get-Credential -Message “$ExecutingUser_FullName, please enter your credentials.” -UserName “$ExecutingUser_Domain\$ExecutingUser_UserName”)
#Define Functions
#Determine The Parent Of An Active Directory Object
Function Get-ADObjectParent ($DistinguishedName)
{
$Parts = $DistinguishedName -Split “(?<![\\]),"
Return $Parts[1..$($Parts.Count – 1)] -Join ","
}
#Make A Backup Copy Of "DomainOUList.xml"
If (Test-Path -Path "$ExportPath") {Copy-Item -Path "$ExportPath" -Destination "$BackupPath" -Force | Out-Null}
#Create "DomainOUList.xml"
$DomainOUList_Create = (New-Item -ItemType File -Path "$ExportPath" -Force).FullName
#Retrieve Organizational Units From Active Directory And Sort The Results Based On CanonicalName
$OUs = Get-ADOrganizationalUnit -Filter * -Credential $Credentials -Properties * -SearchBase $SearchBase -SearchScope Subtree -Server $Server | Select *, @{Name="FriendlyName";Expression={($_.CanonicalName).Split("/")}}, @{Name="Parent";Expression={Get-ADObjectParent -DistinguishedName $_.DistinguishedName}} | Sort-Object CanonicalName
#Export To "DomainOUList.xml" for use with Microsoft Deployment Toolkit
If ($OUs.Count -gt 0)
{
("” + $NewLine) | Out-File -FilePath “$ExportPath” -Append -Encoding utf8
(“” + $NewLine) | Out-File -FilePath “$ExportPath” -Append -Encoding utf8
ForEach ($Item In $OUs)
{
#If You Want To Remove Portions Of The “$Item.FriendlyName” Property, Experiment With The “+ 4″ Value. Example – Change It To + 3, etc… This May Make It Easier To See The Names When Selecting Them During Deployment.
$Item.FriendlyName = (($Item.FriendlyName)[($Item.FriendlyName.GetLowerBound(0) + 4)..($Item.FriendlyName.GetUpperBound(0))] -Join ” \ “)
Write-Host “Now Exporting `”$($Item.FriendlyName)`” to `”$($ExportPath)`”” -BackgroundColor Black -ForegroundColor Yellow
#Comment/Uncomment The Follwing Line If You Want To Make Use Of FriendlyNames, Only One Value May Be Used At A Time!
($Tab + “” + $NewLine + $Tab + $Tab + $($Item.FriendlyName) + $NewLine + $Tab + “” + $NewLine) | Out-File -FilePath “$ExportPath” -Append -Encoding utf8
#Comment/Uncomment The Follwing Line If You Want To Make Use Of DistinguishedNames, Only One Value May Be Used At A Time!
#($Tab + “” + $NewLine + $Tab + $Tab + $($Item.DistinguishedName) + $NewLine + $Tab + “” + $NewLine) | Out-File -FilePath “$ExportPath” -Append -Encoding utf8
}
(“”) | Out-File -FilePath “$ExportPath” -Append -Encoding utf8
}
#Stop logging script output
$NewLine
(Stop-Transcript)
########End Powershell Script
hi
I did try this. But I still do not see drop down for organization list. What am I missing?
I have created XM filea and saved under scripts folder
Some help much appreciated
Thanks
Can we do the same type listing for Join a Domain?
hi, i’ve question. i’ve domain and subdomain and i want to list of domains, how i can do this?