Advertisement
PC_Aide

Create OU from CSV file.ps1

Dec 9th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. -------------------------------------------------------------------------------------------------------------------------
  3.     SRC: https://www.alexandreviot.net/2015/04/27/active-directory-create-ou-using-powershell/
  4.     Elevated: Y | N
  5.     Syntax: ".\Create OU from CSV file.ps1" -FileCSV .\listOU.csv
  6.  
  7.     O/P: https://imgur.com/5clh6Dg
  8.  
  9. ╔════════════listOU.csv════════════════╗
  10. ║ name;path                           ║
  11. ║ #Root                               ║
  12. ║ PC-Aide;DC=PC-Aide,DC=ca            ║
  13. ║ #                                   ║
  14. ║ #OU                                 ║
  15. ║ Admins;OU=PC-Aide,DC=PC-Aide,DC=ca  ║
  16. ║ Groups;OU=PC-Aide,DC=PC-Aide,DC=ca  ║
  17. ║ Users;OU=PC-Aide,DC=PC-Aide,DC=ca   ║
  18. ╚════════════listOU.csv════════════════╝
  19. -------------------------------------------------------------------------------------------------------------------------
  20. ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼
  21.     mp4:
  22. ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼
  23. #>
  24.  
  25. param([parameter(Mandatory=$true)] [String]$FileCSV)
  26. $listOU=Import-CSV $FileCSV -Delimiter ";"
  27. ForEach($OU in $listOU){
  28.  
  29. try{
  30. #Get Name and Path from the source file
  31. $OUName = $OU.Name
  32. $OUPath = $OU.Path
  33.  
  34. #Display the name and path of the new OU
  35. Write-Host -Foregroundcolor Yellow $OUName $OUPath
  36.  
  37. #Create OU
  38. New-ADOrganizationalUnit -Name "$OUName" -Path "$OUPath"
  39.  
  40. #Display confirmation
  41. Write-Host -ForegroundColor Green "OU $OUName created"
  42. }catch{
  43.  
  44. Write-Host $error[0].Exception.Message
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement