Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###
- # PowerShell script for creating one global group in
- # every OU under a defined mainOU.
- #
- #
- # Usage:
- # 1. Run the script
- # 2. Define the mainOU variable asked for
- # 3. Done :-)
- #
- # Created by Danni Randeris <danni@danniranderis.dk>
- ###
- # Define the name for the main OU
- $mainOUName = Read-Host "Please provide your main OU here"
- #######################################
- ## DO NOT CHANGE ANYTHING BELOW HERE ##
- #######################################
- # Get distinguished name for main OU
- $mainOU = (Get-ADOrganizationalUnit -Filter "Name -eq `"$mainOUName`"").DistinguishedName
- # Get each department OU under the main OU
- $departmentOU = Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase $mainOU -SearchScope OneLevel
- # Run through all department OU and create groups
- $departmentOU | foreach {
- $OUName = $_.Name
- Write-Host "Creating Group under: " $OUName
- New-ADGroup -Name $OUName"_grp" -GroupCategory Security -GroupScope Global -Path $_.DistinguishedName
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement