小编Hin*_*nek的帖子

PowerShell:将一个 OU 的所有 AD 用户复制到另一个 OU

我正在尝试将 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,所以请帮忙!

powershell active-directory .net

1
推荐指数
1
解决办法
3472
查看次数

标签 统计

.net ×1

active-directory ×1

powershell ×1