Hi there
This article it’s to show how to create DG (Distribution Groups) from CSV file into ADDS.
We got an export from Lotus Notes Distribution Group (same client) where we have:
- Group Name
- Members: with CN and email (as contacts) on the same columnĀ
Challenges
- create the Distribution Groups from CSV file (as is, with blank spaces on name)
- import members into ADDS Distribution Groups
- import contacts into ADDS Distribution Groups, based on the column A (group name) and column E (members)
Script #1 – Creating Distribution Groups in ADDS from CSV file
###############################################################################################################################################################################################################################################
# Author Thiago Beier thiago.beier@gmail.com
# Version: 1.0 - 2020-07-16
#
# Create Distribution Groups in ADDS
# Create a DG if doesn't exist
# Create all DG with a prefix "D-CA-" from CSV file
# DG groups need mail and proxyaddresses attributes in AD to work after they're synced to AzureAD/Office365 tenant
# You can add, replace, remove any attribute as needeed.
#
# Toronto, CANADA
# Email: thiago.beier@gmail.com
# https://www.linkedin.com/in/tbeier/
# https://twitter.com/thiagobeier
# https://thiagobeier.wordpress.com
###############################################################################################################################################################################################################################################
clear
$dt=get-date -format yyyy-MM-dd-hhmm
Start-Transcript log-$dt.txt
#$file=IMPORT-CSV .\dg1.csv
$file=IMPORT-CSV .\dgroups-members.csv
$dgemail = $null
$dgname = $null
$groupobjid = $null
FOREACH ($line in $file)
{
$dgemail = $line.email+"@thebeier.com"
#$dgemail
$dgname = "D-CA-"+$line.GroupName
write-host "setting DG email address $dgemail to" $dgname -ForegroundColor Green
# If the group exists, inform, if it does not exist also inform.
If (Get-ADGroup -Filter * | where {$_.Name -like $dgname})
{
$dgname
Write-Host "$dgname already exists in Active Directory" -ForegroundColor Green
$groupobjid = (Get-ADGroup -Filter * | where {$_.Name -like "$dgname"}).ObjectGUID
$groupobjid
Set-ADGroup $dgname -Add @{mail = "$dgemail"}
Set-ADGroup $dgname -Add @{proxyAddresses = "SMTP:$dgemail"}
}
Else
{
Write-Host "I am sorry, $dgname does not exist." -ForegroundColor RED
$OUpath="OU=DistributionGroups,DC=thebeier,DC=local"
write-host "creating group:" $dgname -ForegroundColor Yellow
New-ADGroup -Name "$dgname" -SamAccountName "$dgname" -GroupCategory Distribution -GroupScope Universal -Path $OUpath -Description $line.Description
Set-ADGroup $dgname -Add @{mail = "$dgemail"}
Set-ADGroup $dgname -Add @{proxyAddresses = "SMTP:$dgemail"}
}
}
Stop-Transcript
Wait for the next script! Import Contacts into ADDS from CSV fileĀ Coming soon.
Check my Github repository
Check this script and the CSV file example here.
Thanks,