I have a pretty simple script today. All it does is import your Active Directory group information from the CSV file and create the groups based on the information imported. This is pretty much as simple as it gets but very effective for creating multiple groups in different organizational units.
The format of the CSV file is in the code below. If you have questions leave a comment below or on the Youtube video or with the Social Media links below or you can hunt me down and ask in person as well.
<# *** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK *** .DESCRIPTION Read Active Directory group info from groups.csv and create the groups. Example CSV File: GroupName GroupCategory GroupScope OU Finance Security Global OU=_Groups,DC=signalwarrant,DC=local R&D Security Global OU=_Groups,DC=signalwarrant,DC=local IT Security Global OU=_Groups,DC=signalwarrant,DC=local HR Security Global OU=_Groups,DC=signalwarrant,DC=local Executive Security Global OU=_Groups,DC=signalwarrant,DC=local .NOTES File Name: Author: David Hall Contact Info: Website: www.signalwarrant.com Twitter: @signalwarrant Facebook: facebook.com/signalwarrant/ Google +: plus.google.com/113307879414407675617 YouTube Subscribe link: https://www.youtube.com/channel/UCgWfCzNeAPmPq_1lRQ64JtQ?sub_confirmation=1 Requires: Tested: .PARAMETER None .EXAMPLE .\create-groups.ps1 #> $csv = Import-Csv -Path "c:\scripts\groups.csv" ForEach ($item In $csv) { $create_group = New-ADGroup -Name $item.GroupName -GroupCategory $item.GroupCategory -groupScope $item.GroupScope -Path $item.OU Write-Host -ForegroundColor Green "Group $($item.GroupName) created!" }
New-ADGroup : The name provided is not a properly formed account name
At line:5 char:25
+ … ate_group = New-ADGroup -Name $item.GroupName -GroupCategory $item.Gr …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=sp_9-Corpora…cworks,DC=local:String) [New-ADGroup], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServer:1315,Microsoft.ActiveDirectory.Management.Commands.NewADGroup
The OU column contains commas, it must be between double quotes
If you come across the error message below, you need to make sure you have Excel installed on the machine you are using. You maybe able to use other CSV readers or editors but Excel worked for me!
New-ADGroup : Cannot validate argument on parameter ‘Name’. The argument is null or empty. Provide an argument that is not null or empty, and then
try the command again.
At C:\Users\Administrator.SMSJ-CURRIC\Desktop\bulk_ad_group_creation.ps1:5 char:43
+ $create_group = New-ADGroup -Name $item.GroupName -GroupCateg …
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-ADGroup], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.NewADGroup
Thanks awesome script, I am able to create security groups in AD, but I need to update description manually. Can we add one more column in CSV file for update description in group s.
New-ADGroup : Cannot validate argument on parameter ‘GroupCategory’. The argument is null. Provide a valid value for
the argument, and then try running the command again.
At line:5 char:74
+ $create_group = New-ADGroup -Name $item.GroupName -GroupCategory $item.G …
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-ADGroup], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.NewADGro
up
I tried your scrip but it has an issue pulling the OU part any ideas. I have everything just as you have it. if I do it where I manually put in the ou after the -path it work, just wont work when pulling the data field for the CSV file
script can’t read the groupscope field – error “Cannot validate argument on parameter ‘GroupScope’. The argument is null. Supply a non-null argument”
how do we add an option to Check if the Group already exists?