Jump to content

Recommended Posts

Posted

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"

Posted

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

Posted

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 
}

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...