Solved

Creating Security Groups

Posted on 2013-01-25
2
287 Views
Last Modified: 2013-01-25
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
Comment
Question by:Joseph Moody
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38819178
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
 
LVL 22

Author Closing Comment

by:Joseph Moody
ID: 38819405
Just what I needed!

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

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question