3

I have a script which has the following for adding users using a CSV file, in Powershell. Windows Server 2008 R2.

looks like this:

Import-Csv "C:\Users\me\Desktop\users.csv" | Where-Object {$_.Name} |`
 ForEach-Object {`
New-ADUser `
-Name $_."Name" `
-GivenName $_."GivenName" `
-Surname $_."Surname" `
-Description $_."Department" `
-SamAccountName $_."Logon_Username" `
-UserPrincipalName $_."UPN" `
-DisplayName $_."Display_Name" `
-AccountPassword (ConvertTo-SecureString -AsPlainText "P@ssw0rd1!" -Force) `
-Path "OU=Users,OU=Head Office,OU=International,DC=company,DC=com" `
-ChangePasswordAtLogon $true `
-Enabled $true | Enable-ADAccount | `
Add-ADGroupMember "QA_Users" $_."Logon_Username";
}

the script goes through successfully with no error, and the users are added. when I go to AD Users and Computers, I can see the users added correctly. However, when I go to the 'member of' section, it doesn't show the group specified in the script.

I've noticed then if I try to add the user again manually by powershell using add-adgroupmember, the command says 'user is already part of the specified group'.

I've noticed if I wait about 15-20 minutes, then the group will show up. Can someone help me? Thank you!

  • Group membership changes are not classified for urgent replication so it is normal to see the delay. Maybe you can use the -Server switch to point to the same DC that you are viewing in ADUC and you will be able to view the change instantly. – Bin Feb 3 '16 at 16:46
  • @Bin, This should be an answer. Your recommendation to scope changes and queries to a specific server would totally solve OP's issue. Totally. – blaughw Feb 3 '16 at 17:46
5

Group membership changes are not classified for urgent replication so it is normal to see the delay. Maybe you can use the -Server switch to point to the same DC that you are viewing in ADUC and you will be able to view the change instantly.

  • I tried this unfortunately, still no luck :( – 2legit2quit Feb 16 '16 at 18:37
  • @2legit2quit I just tested this and it does work immediately. Can you share your updated code? – Bin Feb 23 '16 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.