copy AdUser with group and manager

adrien FRANSQUIN 1 Reputation point


i have a problem with my script who cretead a new ad user from a other account. because when the new account is cretead the group member and the manager is missing in the user.
my script :

#Import module    
Import-Module activedirectory    
#Set password for new user     
$password = Read-Host -Prompt "Set Password" -AsSecureString    
#Copy user - user01    
$userInstance = Get-ADUser -Filter "Name -eq '_modèle Agence Lyon'" -SearchBase "OU=Office365,OU=Agences,OU=Utilisateurs,OU=Amitel,OU=Domain Controllers,DC=ad,DC=lan"    
#Create a new user from user01    
New-ADUser -SAMAccountName ""  -Instance $userInstance -GivenName "Alexis" -Surname "DUPONT"-DisplayName "Alexis DUPONT" -Name "Alexis DUPONT" -UserPrincipalName "[@](/users/na/?userId=19eb5f6d-bffd-0003-0000-000000000000).fr" -AccountPassword $password -Path "OU=Office365,OU=Agences,OU=Utilisateurs,OU=Amitel,OU=Domain Controllers,DC=ad,DC=lan"     

what i do wrong ?

kinds regards

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,282 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 44,006 Reputation points

    I don't think the "manager" and "memberOf" properties are retrieved by default. You'd have to inform the Get-ADUser that you want them by naming them in the -Properties parameter.

    However, just because you'll be populating the "memberOf" property of the new user won't, I think, actually make the user a member of the groups. In other words, the "members" property of the groups won't be updated to include the user even though the user's memberOf property would lead you to believe that they're a member. You should verify that.

    The same may be true of the user's "manager" property. I'm not sure that simply copying it from the template user to the new user will also update the manager's AD user property "directreports".

    0 comments No comments