1

我的问题是是否可以在企业环境中获取计算机的域名并将其用作 MDT 部署中的计算机名称。

我知道 MDT 可以在此处设置计算机名称:右键单击部署共享 - 规则

我很想使用变量 $CNAME(计算机名称),我可以使用以下 powershell 命令成功获得它作为部署共享设置中“OSDComputerName =”的变量。


这个 ps 脚本给了我正确的名字:

1 获取IP

$IP=((ipconfig | findstr [0-9].\.)[0]).Split()[-1]

2 对 IP 进行 NSLOOKUP

$Lookup=NSLOOKUP $IP

3 使用正则表达式和 -replace 修饰符调整输出以仅包含不带 DNS 后缀的真实计算机名

$regex=$Lookup -match "(^.*\bName\b\:?\s*\b)[\w\d\s\-]*"
$replace1=$regex -replace "Name:    "
$CNAME=$replace1 -replace "*DNSSUFFIX*"

这可能吗?否则,我可以在部署完成后以任何方式使用 PowerShell 脚本重命名计算机吗?例如,我可以使用哪个命令将变量 $CNAME 用作新的计算机名称?

4

1 回答 1

1

以下脚本将使用 IP 地址查询您的 DNS 并获取域中计算机的名称并将其传递回 MDTOSDComputerName

这适用于计算机命名为name.xx.yournamespace.de

将 Windows ISO 中的 nslookup.exe 添加到 WinPE 启动映像(使用 DISM 安装 WinPE WIM 并将 nslookup.exe 复制到 System32 中)

调整你的 customsettings.ini 规则,添加:

UserExit=Setname.vbs
OSDComputerName=#SetName("%IPAddress%")#

将 UserExit 脚本添加到您的 Deploymentshare 脚本文件夹中,为其命名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

调整您的网络的替代品。SetName将被传递回 MDT。

希望这可以帮助某人!

于 2017-09-08T14:38:23.410 回答