I'm trying to copy all users of OU "A" to the OU "B". My PowerShell shot at this is
$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)
}
My problem is, that $user appears to lack the CopyTo method I try to call. As far as I understand PowerShell, $user is an .NET object of the type System.DirectoryServices.DirectoryEntry ... in Visual Studio I find the method CopyTo ... in PowerShell I find none of it's methods, just properties.
I'm just starting with PowerShell, so please help!