Last active
September 7, 2017 00:41
-
-
Save mrajashree/5308b22bd70293adbf607dd0b8d2edea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create multiple AD groups | |
source: http://www.signalwarrant.com/create-active-directory-groups-bulk-csv-w-powershell/ | |
``` | |
$csv = Import-Csv -Path ".\bulk_input2.csv" | |
ForEach ($item In $csv) | |
{ | |
Write-Host "item: $($item)" | |
$create_group = New-ADGroup -Name $item.GroupName -GroupCategory $item.GroupCategory -groupScope $item.GroupScope -Path $item.OU | |
Write-Host -ForegroundColor Green "Group $($item.GroupName) created!" | |
} | |
``` | |
Create multiple AD groups by assigning incremental names | |
``` | |
$csv = Import-Csv -Path ".\bulk_input2.csv" | |
$count=1 | |
ForEach ($item In $csv) | |
{ | |
Write-Host "item: $($item)" | |
$newname = "multiplegroup"+$count | |
Write-Host "name: $($newname)" | |
$count+=1 | |
Write-Host "count: $($count)" | |
$create_group = New-ADGroup -Name $newname -GroupCategory $item.GroupCategory -groupScope $item.GroupScope -Path $item.OU | |
Write-Host -ForegroundColor Green "Group $($item.GroupName) created!" | |
} | |
``` | |
Add user to multiple groups | |
``` | |
Import-Module ActiveDirectory | |
$groups = Get-ADGroup -Filter {name -like "multiplegroup*"} | |
ForEach ($g in $groups) | |
{ | |
Add-ADGroupMember -Identity $g.DistinguishedName -Members "multipleuser1" | |
Write-Host "Group: $($g)" | |
} | |
``` | |
bulk_input2.csv, open in officeCalc with delimiter set to comma | |
GroupName GroupCategory GroupScope OU | |
multiplegroup1 Security Global CN=Users,DC=testad,DC=rancher,DC=io | |
multiplegroup2 Security Global CN=Users,DC=testad,DC=rancher,DC=io |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment