1

How to move a computer to a new OU as a step in SCCM Task Sequence?

Requirements:

  • Powershell instead of VBS
  • No "File" on the sccm client system

As this is a Task Sequence step, the command will be executed locally on the SCCM Client so using the Active-Directory module is not an option unless the module is installed on every system that could be affected by this task.

Command-line execution defaults to CMD.exe, forcing to deal with painful string escape steps.

4

1 回答 1

0

在网上环顾四周,我发现一篇博文详细介绍了 SCCM 允许在任务序列中执行一个名为“运行命令行”的步骤。但是,该博客文章解决方案不是独立的命令行执行。

此外,在尝试使用 Powershell 解决方案将本地主机(任何非域控制器)移动到新 OU 时,我发现了一篇博客文章,其中包含使用 ADSI 而不是 Active-Directory 模块的代码片段。

将这些过程组合到单个命令行执行中,这需要一些时间,但我能够解决将 CMD.exe 字符串解析/转义和 Powershell 字符串解析/转义组合成单个命令行执行的问题,该执行将在 SCCM 中工作任务序列。

  • 在 SCCM2012 中:编辑任务序列时单击添加、常规、“运行命令行”

命令行:

C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -command iex \" `$TargetOU=\"\"OU=TargetOUName,DC=ConglomiCo,DC=com\"\"; `$SysInfo=New-Object -ComObject \"\"ADSystemInfo\"\";`$ComputerDN=`$SysInfo.GetType().InvokeMember(\"\"ComputerName\"\",\"\"GetProperty\"\",`$Null,`$SysInfo,`$Null);`$Computer=[ADSI]\"\"LDAP://`$ComputerDN\"\";`$OU=[ADSI]\"\"LDAP://`$TargetOU\"\";`$Computer.psbase.MoveTo(`$OU);" \"

注意:请务必在“运行命令行”任务中指定具有适当权限的域帐户:

  • SCCM 客户端系统的管理执行权限
  • 移动计算机帐户对象的 AD 权限
  • 对目标 OU 的写入权限

此解决方案在命令行条目中包含目标 OU,但是可以轻松修改以读取可能包含目标 OU DN 的注册表项、文件系统上的文本文件等。

于 2014-04-09T14:41:46.623 回答