#Parameters
$InputFile="import.csv"
#Variables
$errors=0
$success=0
#csv file that contains all groups to create
$InputGroups=Import-csv $InputFile -Delimiter ";"
$InputGroups|
Foreach-Object{
#Importing data
$GroupName=$_."GroupName"
$Destination=$_."DESTINATION"
$Description=$_."DESCRIPTION"
Write-Host "`n Creation du groupe : $GroupName -" -NoNewLine
#AD Group creation
New-ADGroup -name "$GroupName" -groupscope DomainLocal -GroupCategory Security -Description $Description -path $Destination
#Check if group well created
$testADGroup=Get-ADGroup $GroupName
If($testADGroup){
Write-Host " OK" -ForegroundColor:GREEN
$success+=1
}
Else{
Write-Host " KO" -ForegroundColor:RED
$errors+=1
}
}
#Final
$total=$success+$errors
Write-Host "`n `n $total groups created : `n "
Write-Host " - $success" -NoNewLine -ForegroundColor:GREEN
Write-Host " groups created"
Write-Host " - $errors" -NoNewLine -ForegroundColor:RED
Write-Host " groupes not created `n `n "
A quick Powershell script, easy to use, to create a lot of groups from a csv file
You must be logged in to post a comment.