• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Creating Security Groups

I have this script that I have been working on. I am now stuck and could use some help.

Add-PSSnapin Quest.ActiveRoles.ADManagement

$SourceGroup=Read-Host "What is the Software Distribution Group?"

$SchoolGroups= 
    "ALT_$SourceGroup",
    "BHS_$SourceGroup"

$SchoolOUs= 
    "OU=ALT Applications,OU=ALT Groups,OU=Altama Elementary School,OU=Elementary Schools,OU=Domain Sites,DC=GCBE,DC=local", 
    "OU=BHS Applications,OU=BHS Groups,OU=Brunswick High School,OU=High Schools,OU=Domain Sites,DC=GCBE,DC=local"

Foreach ($SchoolGroup in $SchoolGroups) {
New-QADGroup -Name $SchoolGroup -ParentContainer $SchoolOUs -SamAccountName $SchoolGroups -GroupType Security -GroupScope Global
Add-QADGroupMember $SourceGroup $SchoolGroups }

Open in new window


My goal is to prompt for a security group and then have the script create nested sub groups for each group listed in $SchoolGroups and to create them in their corresponding OU ($SchoolOUs).

I am then wanting to add the newly created groups into the $sourcegroup.
0
Joseph Moody
Asked:
Joseph Moody
1 Solution
 
SubsunCommented:
Try this..
Add-PSSnapin Quest.ActiveRoles.ADManagement
$SourceGroup=Read-Host "What is the Software Distribution Group?"
$SchoolGroups= 
    "ALT_$SourceGroup",
    "BHS_$SourceGroup"

Foreach ($SchoolGroup in $SchoolGroups) {
If ($SchoolGroup -match "^ALT_") 
	{$SchoolOUs= "OU=ALT Applications,OU=ALT Groups,OU=Altama Elementary School,OU=Elementary Schools,OU=Domain Sites,DC=GCBE,DC=local"}
ElseIf ($SchoolGroup -match "^BHS_") 
	{$SchoolOUs= "OU=BHS Applications,OU=BHS Groups,OU=Brunswick High School,OU=High Schools,OU=Domain Sites,DC=GCBE,DC=local"}

New-QADGroup -Name $SchoolGroup -ParentContainer $SchoolOUs -SamAccountName $SchoolGroup -GroupType Security -GroupScope Global
}

#After creating the groups you can add the members..
$SchoolGroups | %{Add-QADGroupMember $_ $SchoolGroups}

Open in new window

0
 
Joseph MoodyBlogger and wearer of all hats.Author Commented:
Just what I needed!

I changed the last line to Add-QADGroupMember $SourceGroup $SchoolGroups
0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now