WDS+MDT网络启动自动部署windows(十八)MDT 移动OU组织单位
简介#
加入域时,如果计算机已存在,且OU设置不一致,可能会导致计算机孤立。
使用 Windows 10 (Windows 10) 刷新 Windows 7 计算机 - Windows 10 |Microsoft学习
在刷新过程中,部署共享规则中指定的域加入详细信息将用于将计算机重新加入域。如果 Windows 7 客户端在与 MachineObjectOU 指定的 OU 不同的 OU 中进行域 jonied,则域加入过程最初将失败,然后在不指定 OU 的情况下重试。如果指定的域帐户(例如:MDT_JD)具有限制为特定 OU 的权限,则域加入最终将失败,刷新过程将继续进行,并且客户端计算机对象将在 Active Directory 中孤立。在当前指南中,计算机对象应位于 Contoso > Computers > Workstations 中。 使用 Active Directory 用户和计算机控制台查看计算机对象的位置,并在需要时移动它们。若要诊断 MDT 域加入错误,请参阅客户端计算机上 C:\Windows\Temp\DeploymentLogs 目录中的ZTIDomainJoin.log。
即使我们全新安装,也会有这样的问题。
解决方案#
型号有个大佬给出了一个补丁。
MDT 2013: Moving Computers Into Correct OU on AD Join – the STONYWALL blog
代码#
将计算机移入正确的OU
# Script to move the computer object in AD to the OU supplied as a variable. # Place powershell script in %ScriptRoot% (DeploymentShare\Scripts\) folder. # Example Command line: Powershell.exe -NoProfile -ExecutionPolicy bypass -file MoveToOU.ps1 "%MachineObjectOU%" $OU = $args[0] try { $CompDN = ([ADSISEARCHER]"sAMAccountName=$($env:COMPUTERNAME)$").FindOne().Path $CompObj = [ADSI]"$CompDN" $CompObj.psbase.MoveTo([ADSI]”LDAP://$($OU)”) } catch { $_.Exception.Message ; Exit 1 }
实验记录#
测试换组织单位的安装结果。
该计算机目前在技术部,数据库我改成了技术组,重装一下看看,自动进入哪个组织单位OU
毫不意外,OU并没有改变,未来将是有OA系统等等自动化同步的任务,同步计算机,用户到对应的组织单位,难道重装一下还是错的么?还是时差bug?
尝试让OU自动改变吧。
仍然毫无意外的,我又遇到了中文编码问题。这次是powershell脚本,vbs、wsf脚本的解决方案无效。因为乱码乱的不一样了。变量是通过命令行传过来的,用在线乱码解析无结果。
我再找找,有没有vbs的解决方案吧。
VBS方案#
VBScript:通过命令行参数将计算机对象移动到另一个 OU – CTGlobal (ctglobalservices.com)
' cscript.exe MoveOU.vbs “OU=HQ,dc=woodgrovebank,dc=com” ' //*************************************************************************** ' //*************************************************************************** ' // ***** Script Header ***** ' // ' // Solution: ConfigMgr ' // File: MoveComputerToCorrectOU.vbs ' // Author: Jakob Gottlieb Svendsen, Coretech A/S. https://blog.ctglobalservices.com ' // Purpose: Move computer to the correct OU that remains in variable MachineObjectOU ' // Run inside TS after install ' // ' // Usage: MoveComputerToCorrectOU.vbs ' // ' // ' // CORETECH A/S History: ' // 0.0.1 JGS 17/12/2009 Created initial version. ' // 0.0.2 MIP 17/03/2009 Added feature to add argument to script ' // 0.0.3 JGS 02/12/2010 Changed to ADSystemInfo for the DN retrieval, instead of a homemade function. ' // Thanks to Nico_ at Technet Forums ' // ' // Customer History: ' // ' // ***** End Header ***** ' //*************************************************************************** '//---------------------------------------------------------------------------- '// Main routines '//---------------------------------------------------------------------------- On Error Resume Next 'Get MachineObjectOU Value Set wshNetwork = CreateObject("WScript.Network") Set oFso = CreateObject("Scripting.FileSystemObject") Set objSysInfo = CreateObject( "ADSystemInfo" ) Set ArgObj = WScript.Arguments 'Use first argument as target OU strMachineObjectOU = ArgObj(0) strComputerDN = objSysInfo.ComputerName nComma = InStr(strComputerDN,",") strCurrentOU = Mid(strComputerDN,nComma+1) strComputerName = Left(strComputerDN,nComma - 1) 'If current ou is different than target OU. Move object If UCase(strCurrentOU) <> UCase(strMachineObjectOU) Then Set objNewOU = GetObject("LDAP://" & strMachineObjectOU) Set objMoveComputer = objNewOU.MoveHere("LDAP://" & strComputerDN, strComputerName) End If '//---------------------------------------------------------------------------- '// End Script '//----------------------------------------------------------------------------
VBS方案应该是可以继续使用windows-1252 转 UTF-8解决方案的。
试试吧。虽然他也是命令行传输变量,但是vbs,也就是wsf,我们可以自己获取变量。
能看到第十八篇,您也是够厉害的了,代码会改了吧。我就不贴了。
移动组织单位,需要管理员权限,请在任务中配置。
作者:上官飞鸿
出处:https://www.cnblogs.com/jackadam/p/18189782
版权:本作品采用「知识共享-署名-非商业性-禁止演绎(CC-BY-NC-ND)」许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
2022-05-13 证书服务(五)windowsCA中心