the_wuigi Posted September 9, 2015 Posted September 9, 2015 Guys can someone please tell me what entry I would need to add to this script so that it added an extra group where there is adgroup="ou1 group1" for eg I want to add another existing group so on each line it would maybe read something like adgroup="ou1 group1" adgroup="ou1 group2" I have zero knowledge of powershell I'm just trying to edit an existing bulk user import script and want the users to be added to 2 existing groups, the script at the moment only adds them to the the one group per ou ou1 group1 ou2 group1 ou3 group1 if ($sitecode -eq "test1") { $FileServer = "server1" $oupath="OU=ou1 acme1,OU=test,OU=abc,DC=abcd,DC=bluesky,DC=local" $filepath="my file path" $adgroup="ou1 group1" } if ($sitecode -eq "test2") { $FileServer = "server2" $oupath="OU=ou2 acme2,OU=test,OU=abc,DC=abcd,DC=bluesky,DC=local" $filepath="my file path" $adgroup="ou2 group1" } if ($sitecode -eq "test3") { $FileServer = "server3" $oupath="OU=ou3 acme3,OU=test,OU=abc,DC=abcd,DC=bluesky,DC=local" $filepath="my file path" $adgroup="ou3 group1"
halbaradkenafin Posted September 9, 2015 Posted September 9, 2015 Is there more code for this script? This just appears to be setting the basic variables and not actually adding the users to groups.
the_wuigi Posted September 9, 2015 Author Posted September 9, 2015 I maybe over complicating things here so let me try again if ($sitecode -eq "test1") { $FileServer = "server1" $oupath="OU=ou1 acme1,OU=test,OU=abc,DC=abcd,DC=bluesky,DC=local" $filepath="my file path" $adgroup="ou1 group1" On the line $adgroup=ou1 group1 This adds users to an existing group called ou1 group1 I want to add the users to an additional existing group lets call it ou1 group2
Arthur Posted September 9, 2015 Posted September 9, 2015 As @halbaradkenafin mentioned above, your scripts are only setting variables rather than adding users to groups. You're going to need to use Add-ADPrincipalGroupMembership or Add-ADGroupMember (depending on your script) to actually add users to one or more groups. e.g. $SiteCode = "Test2" $Users = Get-ADUser -Filter * -SearchBase "OU=Students,DC=example,DC=net" Switch ($SiteCode) { 'Test1' { $Group1 = "ou1-g1" $Group2 = "ou1-g2" } 'Test2' { $Group1 = "ou2-g1" $Group2 = "ou2-g2" } 'Test3' { $Group1 = "ou3-g1" $Group2 = "ou3-g2" } } ForEach ($User in $Users) { Add-ADPrincipalGroupMembership -Identity $User.SamAccountName -MemberOf $Group1,$Group2 }
the_wuigi Posted September 10, 2015 Author Posted September 10, 2015 I see what you're saying now guy's and have managed to resolve, thanks for the input.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now