#--------------------------------------------------------------------------------------- #Script name :- CreateADGroup.ps1 # #Script author :- Ian Ballard #Version history. #Version number | Date | Author | Comments #1.00 | 07/11/2014 | Ian Ballard | Initial version. #--------------------------------------------------------------------------------------- $ver = $host | select version if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"} #Include the PowerShell snap-ins & imports that will be needed. Import-Module ActiveDirectory function CreateADGroup( [string] $ADGroup, [string] $ADGroupDisplayName, [string] $ADGroupDescription, [string] $ADOUPath ) { try { get-adgroup $ADGroup | out-null if ( $debug -eq $true ) { write-host -f $debugColourStepIgnored "The AD Group $ADGroup is already in Active directory, skipping this step." } } catch { New-ADGroup -Name $ADGroup -GroupCategory Security -GroupScope Global -DisplayName $ADGroupDisplayName -Description $ADGroupDescription -path $ADOUPath if ( $debug -eq $true ) { write-host -f $debugColour "The AD Group $ADGroup has been created in Active directory." } } } $ConfirmPreference = "None" # #Debug option. # $debug = $true $debugColour = "green" $debugColourStepIgnored = "yellow" # # # #AD Group information for the owners of the site. $ADGroup = "New AD group" $ADDisplayName = "New AD group display name" $ADDisplayDescription = "This AD group was created via a PowerShell script." $ADOUPath = "OU=DEV,OU=Development-Managed Applications,OU=Security,OU=Groups,DC=development,DC=local" CreateADGroup ($ADGroup) ($ADDisplayName) ($ADDisplayName) ($ADOUPath)