Question : How do I Use Powershell to create Multiple Global, Domain Local, and Universal Distribution Active Directory Groups?

Hello All,

I am absolutely new to PowerShell and I am trying to get up to speed. I am trying to find or create a script that would look in a .CSV file and create (approx 400) Domain Local groups. I would like to repeat the process (it can be multiple scripts) for Distribution and Global Groups. Additionally, I would like to specify that the Domain Local groups be placed in an OU called "Domain Local Groups" under an OU called "Domain Groups" in our AD environment--and then place the Global Groups in a sub OU called "Global Groups" under an OU called "Domain Groups", and the Universal Distribution Groups be placed in a sub OU called "Distribution Groups" under an OU called "Domain Groups".

Thanks in advance for everyone's help and patience!!

Answer : How do I Use Powershell to create Multiple Global, Domain Local, and Universal Distribution Active Directory Groups?


Hey,

The first thing I'd do is grab the PowerShell CmdLets from Quest here (they're free):

http://www.quest.com/powershell/

Once you have that you can pipe your CSV or text file into the New-QADGroup command.

For example. If you had a list in a text file which looked like this:

Group 1
Group 2
Group 3

The command could look something like this:

$OU = "OU=Distribution Groups,OU=Domain Groups,DC=yourdomain,DC=com"
$GroupType = "Distribution"
$GroupScope = "Universal"

Get-Content "TextFile.txt" | %{ `
  New-QADGroup -Name $_ -ParentContainer $OU -GroupType $GroupType -GroupScope $GroupScope }

Where $_ is the current object in the pipeline, in this case a line in the text file. You can also import from a CSV file in much the same way.

Full syntax for the New-QADGroup command can be viewed with "Get-Help New-QADGroup -Detailed | more".

Note that this doesn't cover mail enabling groups if that is a requirement. You'd have to let us know the version of Exchange for that, and it's only easy in PowerShell if it's Exchange 2007.

Chris
Random Solutions  
 
programming4us programming4us