<#Created By - Abhishek Bansal
Script Usage - Creating new AD Groups.
Pre requisites :: Setup a Input.csv file containing details such as Group name, Category, Description, Group type and Path. Once done, Copy all the code into a text file, save it with an extension ".PS1". Once saved, run this script as Administrator.
Execution & Outputs :: Once executed, AD Groups will be created along with an output file named "Logs_date" containing all the results.#>
#Below is the snip of CSV file, (don't change the headers of each columns).
$groupdetails = Import-Csv .\Input.csv
$date = $(Get-Date -Format "dd_MM_yy")+".csv"
foreach($group in $groupdetails)
{
try
{
New-ADGroup -Name $group.Name -GroupScope $group.Scope -GroupCategory $group.Category -Path $group.Path -Description $group.Description -PassThru | Select Name,@{n=("Status");e={("Created under")}},DistinguishedName | Export-Csv ./Logs_$date -Append -NoTypeInformation
}
catch
{
$group | Select-Object -Property @{n=("Name");e={($group.Name)}},@{n=("Status");e={("already exist under ")}},@{n="DistinguishedName";e={((Get-ADGroup -Identity $group.Name).DistinguishedName)}} | Export-Csv ./Logs_$date -Append -NoTypeInformation
}
}
Sample Output after Groups creation