My question is if it is possible to obtain the Domain Name of a computer in a Enterprise environment and use it as computer name in a MDT deployment.
I am aware that MDT has an option for setting the computer name here: Right cklick on Deployment Share - Rules
I would love to use the variable $CNAME (Computer Name) which I can successfully obtain using the follwing powershell commands as a variable for “OSDComputerName=“ in the deploymentshare settings.
This ps script gets me the right name:
1 Get IP
$IP=((ipconfig | findstr [0-9].\.)[0]).Split()[-1]
2 Do NSLOOKUP of IP
$Lookup=NSLOOKUP $IP
3 Adjust output with regular expressions and -replace modifiers to only contain the real computername without DNS suffix
$regex=$Lookup -match "(^.*\bName\b\:?\s*\b)[\w\d\s\-]*"
$replace1=$regex -replace "Name: "
$CNAME=$replace1 -replace "*DNSSUFFIX*"
Is this possible? Otherwise, can I use the PowerShell Script in any way to rename the computer after the deployment has finished? Eg which command can I use to use the variable $CNAME as new computer name?
The following Script will use the IP Adress to query your DNS and get the name of the Computer in your Domain and pass it back to MDT as OSDComputerName
This works in an environment where the computers are named like name.xx.yournamespace.de
Add an nslookup.exe from a Windows ISO to your WinPE Boot Image (mount WinPE WIM with DISM and copy nslookup.exe into System32)
Adjust your customsettings.ini Rules, add:
UserExit=Setname.vbs
OSDComputerName=#SetName("%IPAddress%")#
Add a UserExit Script to your Deploymentshare Scripts-Folder, name it Setname.vbs
Function UserExit(sType, sWhen, sDetail, bSkip)
UserExit = Success
End Function
Function SetName(sIP)
Dim rName
Set objShell = createobject("wscript.shell")
strParams = "%comspec% /c nslookup " & sIP & ""
Set objExecObj = objShell.exec(strParams)
Do While Not objExecObj.StdOut.AtEndOfStream
strText = objExecObj.StdOut.Readline()
If instr(strText, "dns-9") Then
strServer = trim(replace(strText,"(null):",""))
Elseif instr (strText, "xx.yournamespace.de") Then
strhost = trim(replace(strText,"(null)",""))
End if
Loop
rName = replace(strhost, ".xx.yournamespace.de", "")
SetName = rName
End Function
Adjust replacements to your Network. SetName
will be passed back to MDT.
Hopefully this helps someone!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.