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-SER VERNAME
DLG-RemoteDesktopUsers-SER VERNAME
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.
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-SER
DLG-RemoteDesktopUsers-SER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
}
}
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.