我正在尝试将 OU“A”的所有用户复制到 OU“B”。我的 PowerShell 拍摄是
$sourceEntry = [ADSI]"LDAP://OU=A,DC=demo,DC=com"
$targetEntry = [ADSI]"LDAP://OU=B,DC=demo,DC=com"
$searcher = New-Object DirectoryServices.DirectorySearcher($sourceEntry)
$searcher.Filter = "(objectClass=user)"
$results = $searcher.FindAll()
foreach($result in $results) {
$user = $result.GetDirectoryEntry()
$user.CopyTo($targetEntry)
}
Run Code Online (Sandbox Code Playgroud)
我的问题是, $user 似乎缺少我尝试调用的 CopyTo 方法。据我了解 PowerShell,$user 是 System.DirectoryServices.DirectoryEntry 类型的 .NET 对象……在 Visual Studio 中我找到了 CopyTo 方法……在 PowerShell 中我没有找到任何方法,只是属性。
我刚开始使用 PowerShell,所以请帮忙!