copy AdUser with group and manager

adrien FRANSQUIN 1 Reputation point
2021-11-25T10:02:54.017+00:00

hi,

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 "a.dupont"  -Instance $userInstance -GivenName "Alexis" -Surname "DUPONT"-DisplayName "Alexis DUPONT" -Name "Alexis DUPONT" -UserPrincipalName "a.dupont[@](/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,389 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 45,096 Reputation points
    2021-11-25T20:24:35.987+00:00

    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