Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- -------------------------------------------------------------------------------------------------------------------------
- SRC: https://www.alexandreviot.net/2015/04/27/active-directory-create-ou-using-powershell/
- Elevated: Y | N
- Syntax: ".\Create OU from CSV file.ps1" -FileCSV .\listOU.csv
- O/P: https://imgur.com/5clh6Dg
- ╔════════════listOU.csv════════════════╗
- ║ name;path ║
- ║ #Root ║
- ║ PC-Aide;DC=PC-Aide,DC=ca ║
- ║ # ║
- ║ #OU ║
- ║ Admins;OU=PC-Aide,DC=PC-Aide,DC=ca ║
- ║ Groups;OU=PC-Aide,DC=PC-Aide,DC=ca ║
- ║ Users;OU=PC-Aide,DC=PC-Aide,DC=ca ║
- ╚════════════listOU.csv════════════════╝
- -------------------------------------------------------------------------------------------------------------------------
- ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼
- mp4:
- ◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼
- #>
- param([parameter(Mandatory=$true)] [String]$FileCSV)
- $listOU=Import-CSV $FileCSV -Delimiter ";"
- ForEach($OU in $listOU){
- try{
- #Get Name and Path from the source file
- $OUName = $OU.Name
- $OUPath = $OU.Path
- #Display the name and path of the new OU
- Write-Host -Foregroundcolor Yellow $OUName $OUPath
- #Create OU
- New-ADOrganizationalUnit -Name "$OUName" -Path "$OUPath"
- #Display confirmation
- Write-Host -ForegroundColor Green "OU $OUName created"
- }catch{
- Write-Host $error[0].Exception.Message
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement