Link to home
Start Free TrialLog in
Avatar of Can
Can

asked on

Create bulk AD groups from CSV.

Hi All,

I have around 100 servers in my test environment. I would like to create 2 Active Directory domain local security groups for each server. 1 for local admin rights and 1 for remote desktop users. Groups can look like:

DLG-LocalAdministrator-SERVERNAME
DLG-RemoteDesktopUsers-SERVERNAME

I have an active directory export of these servers in a CSV file. How can i automate to create those groups with each servername in them?

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Can
Can

ASKER

Thank you! worked like a charm. Just the $targetOU variable wasnt used. I've added it to the new-adgroup cmdlet.

You are awesome.


Sorry; for the sake of completeness (and for anybody else finding this), here's the version with the missing argument (-Path):
$computerList = Import-Csv -Path 'C:\Temp\ComputerList.csv'
$groupNames = @( # The {0} will be replaced with the computer name
	'DLG-LocalAdministrator-{0}'
	'DLG-RemoteDesktopUsers-{0}'
)
$targetOU = 'OU=MyDLGroups,OU=Groups,DC=domain,DC=com'

$computerList | Select-Object -ExpandProperty 'Name' | ForEach-Object {
	$computerName = $_
	ForEach ($groupName in $groupNames) {
		$name = $groupName -f $computerName
		$null = New-ADGroup -Name $name -SamAccountName $name -GroupCategory Security -GroupScope DomainLocal-Path $targetOU -Verbose -WhatIf
	}
}

Open in new window