1

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? E.g. which command can I use to use the variable $CNAME as new computer name?

karkraeg
  • 445
  • 4
  • 18
  • I believe that you can use the Rename-Computer -ComputerName $Computer -NewName $NewComputerName once the computer is rebuilt, I'm not sure where your getting the name from before the system is built though? – Nick Eagle Oct 16 '15 at 12:07
  • That command needs PowerShell 3.0 to be installed (I need to run this for Windows 7 deployment) and in my tests it doesn’t even work with PS3.0 installed, most likely due to the computer I tested it on being in the domain at the time being. Will test next week if rename-computer -newname does work when the computer ist not in the domain. Anyway, this needs PowerShell 3.0 to be deployed first which I would like to avoid… Thanks for your input! – karkraeg Oct 17 '15 at 10:39

1 Answers1

1

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!

karkraeg
  • 445
  • 4
  • 18