我已拼凑在一起下面的PowerShell脚本,但是当我在我的DC运行它我得到下面的错误信息。
我的总体目标是让脚本在计算机OU中的任何工作站上工作,并将其移动到伦敦OU父系中的子OU中的Workstations OU。
任何帮助,将不胜感激。
Powershell脚本
$computerstomove = Get-ADComputer -LDAPFilter "(name=TCWSTEST)" -SearchBase "CN=computers,DC=temporis,DC=corp" foreach ($computertomove in $computerstomove) { Move-ADObject $computertomove -TargetPath "OU=London,OU=Workstations,DC=temporis,DC=corp" }
错误消息:
Move-ADObject : The operation could not be performed because the object's parent is either uninstantiated or deleted At \\tcws40\c$\Scripts\Workstation move.ps1:4 char:2 + Move-ADObject $computertomove -TargetPath "OU=London,OU=Workstations,DC=tempori ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (CN=TCWSTEST,CN=...emporis,DC=corp:ADComputer) [Move-ADObject], ADException + FullyQualifiedErrorId : ActiveDirectoryServer:8329,Microsoft.ActiveDirectory.Management.Commands.MoveADObject
首先,不需要不必要的foreach 。 这应该工作得很好:
Get-ADComputer TCWSTEST | Move-ADObject -TargetPath "OU=London,OU=Workstations,DC=temporis,DC=corp"
其次,我在自己的环境中testing了两种方式(你的和我的),他们都没有错误地工作。 您是否证实,如果“对象的父母未被证实或被删除”是真实的? 仔细检查您的"OU=London,OU=Workstations,DC=temporis,DC=corp"的DN,因为如果您在DN中有拼写错误,您将收到此错误消息。
最后,为了让我的生活变得更加简单,我改变了默认文件夹,把PC添加到域时的位置。 我在Powershell中的DC上使用了redircmp命令,它工作得很好。
redircmp“OU =工作站,OU =伦敦,DC = temporis,DC = corp”