Try {
Import-Module ActiveDirectory -ErrorAction Stop
}
Catch {
Write-Host "[ERROR]`t ActiveDirectory Module couldn't be loaded. Script will stop!" -ForegroundColor Red
Exit 1
}
$path = Split-Path -parent $MyInvocation.MyCommand.Definition
$newpath = $path + "\creategroups.csv"
$list = Import-Csv $newpath
Function Start-Commands {
Create-Groups
}
Function Create-Groups {
foreach ($item in $list) {
If ($item.GroupName -eq "") {
Write-Host "[ERROR]`t Please provide valid group details." -ForegroundColor Red
} Else {
$item.ID = $ou
New-ADGroup -Name $item.GroupName path OU=$ou,DC=company,DC=com -GroupCategory Security -GroupScope DomainLocal
Write-Host "[INFO]`t Created new group : $($item.GroupName)" -ForegroundColor Green
} }
}
Write-Host "STARTED SCRIPT`r`n" -ForegroundColor Cyan
Start-Commands
Write-Host "STOPPED SCRIPT" -ForegroundColor Cyan
New-ADGroup : The server is unwilling to process the request
At C:\Users\t-user-aws\Desktop\test\CreateGroups.ps1:29 char:5
+ New-ADGroup -Name $item.GroupName path 'OU=$item.ID,DC=DC=company, ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=TestGroupB,O...as,DC=com:String) [New-ADGroup], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.NewADGroup