Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. ###
  2. # PowerShell script for creating one global group in
  3. # every OU under a defined mainOU.
  4. #
  5. #
  6. # Usage:
  7. # 1. Run the script
  8. # 2. Define the mainOU variable asked for
  9. # 3. Done :-)
  10. #
  11. # Created by Danni Randeris <danni@danniranderis.dk>
  12. ###
  13.  
  14. # Define the name for the main OU
  15. $mainOUName = Read-Host "Please provide your main OU here"
  16.  
  17.  
  18. #######################################
  19. ## DO NOT CHANGE ANYTHING BELOW HERE ##
  20. #######################################
  21.  
  22. # Get distinguished name for main OU
  23. $mainOU = (Get-ADOrganizationalUnit -Filter "Name -eq `"$mainOUName`"").DistinguishedName
  24.  
  25. # Get each department OU under the main OU
  26. $departmentOU = Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase $mainOU -SearchScope OneLevel
  27.  
  28. # Run through all department OU and create groups
  29. $departmentOU | foreach {
  30. $OUName = $_.Name
  31. Write-Host "Creating Group under: " $OUName
  32.  
  33. New-ADGroup -Name $OUName"_grp" -GroupCategory Security -GroupScope Global -Path $_.DistinguishedName
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement