<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Active-Directory on HiDa</title><link>https://www.0niu.cn/tags/active-directory/</link><description>Recent content in Active-Directory on HiDa</description><generator>Hugo -- gohugo.io</generator><language>zh</language><lastBuildDate>Tue, 09 Sep 2025 23:45:00 +0000</lastBuildDate><atom:link href="https://www.0niu.cn/tags/active-directory/index.xml" rel="self" type="application/rss+xml"/><item><title>redirusr 和 redircmp — Active Directory 默认容器重定向</title><link>https://www.0niu.cn/posts/redirusr-redircmp-active-directory-default-container-redirection/</link><pubDate>Tue, 09 Sep 2025 23:45:00 +0000</pubDate><guid>https://www.0niu.cn/posts/redirusr-redircmp-active-directory-default-container-redirection/</guid><description>&lt;p>Active Directory（AD）新建用户和计算机时，默认存放在 &lt;code>CN=Users&lt;/code> 和 &lt;code>CN=Computers&lt;/code> 容器中。这两个是&lt;strong>容器（Container）&lt;strong>而非&lt;/strong>组织单元（OU）&lt;/strong>，无法直接应用组策略（GPO）。在生产环境中，通常需要将默认位置指向自定义 OU，以便统一管理策略和权限。&lt;/p>
&lt;p>Windows Server 提供了 &lt;code>redirusr.exe&lt;/code> 和 &lt;code>redircmp.exe&lt;/code> 两个内置工具来完成这一操作。&lt;/p></description><content>&lt;p>Active Directory（AD）新建用户和计算机时，默认存放在 &lt;code>CN=Users&lt;/code> 和 &lt;code>CN=Computers&lt;/code> 容器中。这两个是&lt;strong>容器（Container）&lt;strong>而非&lt;/strong>组织单元（OU）&lt;/strong>，无法直接应用组策略（GPO）。在生产环境中，通常需要将默认位置指向自定义 OU，以便统一管理策略和权限。&lt;/p>
&lt;p>Windows Server 提供了 &lt;code>redirusr.exe&lt;/code> 和 &lt;code>redircmp.exe&lt;/code> 两个内置工具来完成这一操作。&lt;/p>
&lt;h2 id="为什么需要重定向">为什么需要重定向&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>对比&lt;/th>
&lt;th>Users / Computers 容器&lt;/th>
&lt;th>自定义 OU&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>类型&lt;/td>
&lt;td>Container（容器）&lt;/td>
&lt;td>OU（组织单元）&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>GPO 链接&lt;/td>
&lt;td>❌ 不支持&lt;/td>
&lt;td>✅ 支持&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>委派控制&lt;/td>
&lt;td>❌ 不支持&lt;/td>
&lt;td>✅ 支持&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>典型用途&lt;/td>
&lt;td>AD 内置账户、域控制器&lt;/td>
&lt;td>按部门/角色组织管理对象&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;blockquote>
&lt;p>新建用户时如果忘记选择目标 OU，对象就会落入默认容器，导致策略未生效。重定向可以从根本上避免这个问题。&lt;/p>
&lt;/blockquote>
&lt;h2 id="原理wellknownobjects-属性">原理：wellKnownObjects 属性&lt;/h2>
&lt;p>重定向的本质是修改域根对象的 &lt;code>wellKnownObjects&lt;/code> 属性。AD 通过该属性记录几个&lt;strong>知名容器&lt;/strong>的 DN：&lt;/p>
&lt;ul>
&lt;li>&lt;code>CN=Users&lt;/code> → 新建用户默认位置&lt;/li>
&lt;li>&lt;code>CN=Computers&lt;/code> → 新计算机加入域时的默认位置&lt;/li>
&lt;/ul>
&lt;p>&lt;code>redirusr&lt;/code> 和 &lt;code>redircmp&lt;/code> 只是修改这个属性的便捷工具，效果等同于用 ADSI Edit 或 LDP 手动修改。&lt;/p>
&lt;h2 id="使用方法">使用方法&lt;/h2>
&lt;p>两个工具位于域控制器上的 &lt;code>%SystemRoot%\System32&lt;/code> 目录下，语法完全一致。&lt;/p>
&lt;h3 id="redirusr--重定向用户默认容器">redirusr — 重定向用户默认容器&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>redirusr &lt;span style="color:#e6db74">&amp;#34;OU=Staff,DC=example,DC=com&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>执行后，所有新建用户将默认放入 &lt;code>OU=Staff,DC=example,DC=com&lt;/code>。&lt;/p>
&lt;h3 id="redircmp--重定向计算机默认容器">redircmp — 重定向计算机默认容器&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>redircmp &lt;span style="color:#e6db74">&amp;#34;OU=Workstations,DC=example,DC=com&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>执行后，新计算机加入域时将默认放入 &lt;code>OU=Workstations,DC=example,DC=com&lt;/code>。&lt;/p>
&lt;h3 id="验证">验证&lt;/h3>
&lt;p>通过 ADSI Edit 查看：&lt;/p>
&lt;ol>
&lt;li>打开 ADSI Edit → 连接到默认命名上下文&lt;/li>
&lt;li>右键点击域根节点（如 &lt;code>DC=example,DC=com&lt;/code>）→ 属性&lt;/li>
&lt;li>找到 &lt;code>wellKnownObjects&lt;/code> 属性&lt;/li>
&lt;li>确认 &lt;code>CN=Users&lt;/code> 和 &lt;code>CN=Computers&lt;/code> 对应的 DN 已更新&lt;/li>
&lt;/ol>
&lt;p>也可以用 PowerShell 快速查看：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>Get-ADDomain | Select-Object UsersContainer, ComputersContainer
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;blockquote>
&lt;p>重定向后此命令会返回新的 OU 路径。&lt;/p>
&lt;/blockquote>
&lt;h2 id="完整示例">完整示例&lt;/h2>
&lt;p>假设域名为 &lt;code>corp.example.com&lt;/code>，计划结构如下：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>DC=corp,DC=example,DC=com
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── OU=Accounts ← 用户默认位置
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>│ ├── OU=Admins
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>│ └── OU=Employees
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── OU=Workstations ← 计算机默认位置
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>│ ├── OU=Laptops
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>│ └── OU=Desktops
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── OU=Servers
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── OU=Groups
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── CN=Users ← 原默认容器（保留，不可删除）
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>└── CN=Computers ← 原默认容器（保留，不可删除）
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>执行：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 在域控制器上以域管理员身份运行&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>redirusr &lt;span style="color:#e6db74">&amp;#34;OU=Accounts,DC=corp,DC=example,DC=com&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>redircmp &lt;span style="color:#e6db74">&amp;#34;OU=Workstations,DC=corp,DC=example,DC=com&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>之后新建用户 &lt;code>john&lt;/code>，会自动出现在 &lt;code>OU=Accounts&lt;/code> 下而非 &lt;code>CN=Users&lt;/code>。&lt;/p>
&lt;h2 id="注意事项">注意事项&lt;/h2>
&lt;h3 id="1-不可逆">1. 不可逆&lt;/h3>
&lt;p>重定向是&lt;strong>单向操作&lt;/strong>，微软不提供撤销命令。如需回退，只能通过 ADSI Edit 手动将 &lt;code>wellKnownObjects&lt;/code> 中的 DN 改回 &lt;code>CN=Users&lt;/code> / &lt;code>CN=Computers&lt;/code>。&lt;/p>
&lt;h3 id="2-原容器仍存在">2. 原容器仍存在&lt;/h3>
&lt;p>&lt;code>CN=Users&lt;/code> 和 &lt;code>CN=Computers&lt;/code> 容器&lt;strong>不会被删除&lt;/strong>，其中的现有对象也不受影响。已有用户/计算机停留在原位，只有&lt;strong>后续新建&lt;/strong>的对象才会进入新 OU。&lt;/p>
&lt;p>如需将已有对象迁移到新 OU：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 批量移动 CN=Users 下的用户到新 OU&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Get-ADUser -Filter * -SearchBase &lt;span style="color:#e6db74">&amp;#34;CN=Users,DC=corp,DC=example,DC=com&amp;#34;&lt;/span> |
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Move-ADObject -TargetPath &lt;span style="color:#e6db74">&amp;#34;OU=Accounts,DC=corp,DC=example,DC=com&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 批量移动 CN=Computers 下的计算机到新 OU&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Get-ADComputer -Filter * -SearchBase &lt;span style="color:#e6db74">&amp;#34;CN=Computers,DC=corp,DC=example,DC=com&amp;#34;&lt;/span> |
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Move-ADObject -TargetPath &lt;span style="color:#e6db74">&amp;#34;OU=Workstations,DC=corp,DC=example,DC=com&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3-目标-ou-必须已存在">3. 目标 OU 必须已存在&lt;/h3>
&lt;p>执行前确保目标 OU 已创建，否则会报错：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-powershell" data-lang="powershell">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 预先创建 OU&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>New-ADOrganizationalUnit -Name &lt;span style="color:#e6db74">&amp;#34;Accounts&amp;#34;&lt;/span> -Path &lt;span style="color:#e6db74">&amp;#34;DC=corp,DC=example,DC=com&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>New-ADOrganizationalUnit -Name &lt;span style="color:#e6db74">&amp;#34;Workstations&amp;#34;&lt;/span> -Path &lt;span style="color:#e6db74">&amp;#34;DC=corp,DC=example,DC=com&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="4-不影响手动指定-ou">4. 不影响手动指定 OU&lt;/h3>
&lt;p>通过 ADUC、&lt;code>New-ADUser&lt;/code>、&lt;code>New-ADComputer&lt;/code> 等工具&lt;strong>手动指定了目标 OU 的操作不受影响&lt;/strong>。重定向只改变不指定位置时的默认行为。&lt;/p>
&lt;h3 id="5-需要域管理员权限">5. 需要域管理员权限&lt;/h3>
&lt;p>执行 &lt;code>redirusr&lt;/code> 和 &lt;code>redircmp&lt;/code> 需要域管理员（Domain Admins）权限。&lt;/p>
&lt;h2 id="与其他方法的对比">与其他方法的对比&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>方法&lt;/th>
&lt;th>优点&lt;/th>
&lt;th>缺点&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>redirusr / redircmp&lt;/strong>&lt;/td>
&lt;td>简单一行命令，微软官方工具&lt;/td>
&lt;td>不可逆，需手动迁移已有对象&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>ADSI Edit 修改 wellKnownObjects&lt;/strong>&lt;/td>
&lt;td>更灵活，可回退&lt;/td>
&lt;td>操作复杂，容易出错&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>脚本创建时指定 OU&lt;/strong>&lt;/td>
&lt;td>完全可控&lt;/td>
&lt;td>无法防止 ADUC 图形界面忘记选择&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Powershell 策略审计&lt;/strong>&lt;/td>
&lt;td>可检测遗漏&lt;/td>
&lt;td>需要额外部署，非根本解决&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>对于大多数场景，&lt;code>redirusr&lt;/code> + &lt;code>redircmp&lt;/code> 是最简单直接的方案。&lt;/p>
&lt;h2 id="最佳实践">最佳实践&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>建域时就执行&lt;/strong>：在新建域之后、创建大量用户之前完成重定向&lt;/li>
&lt;li>&lt;strong>预先创建好 OU 结构&lt;/strong>：规划好组织架构后再执行&lt;/li>
&lt;li>&lt;strong>立即迁移已有对象&lt;/strong>：避免部分对象在新 OU、部分在旧容器造成混乱&lt;/li>
&lt;li>&lt;strong>记录变更&lt;/strong>：在运维文档中记录重定向操作，方便后续排查&lt;/li>
&lt;li>&lt;strong>验证 GPO 生效&lt;/strong>：重定向后创建测试用户/计算机，确认链接到 OU 的 GPO 正常应用&lt;/li>
&lt;/ol></content></item></channel></rss>