Made a script to dynamically create distribution groups from a CSV file. Creating the group, then setting some of it's parameters afterward, mainly conditionalcustomattributes to match with users and thus add as members.
Testing went well, but when I ran the script on the entire file, only a handful of groups were created correctly when it came to the Recipient Filter value.
Including screenshots to see the desired outcome which worked for some, and the outcome for most.
This is the script:
#pull secure cred#
$username = "[email protected]"
$pwdTxt = Get-Content "C:\temp\PSExpPw.txt"
$securePwd = $pwdTxt | ConvertTo-SecureString
$PScred2 = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd
#Connect exchange
Connect-ExchangeOnline -credential $Pscred2
$CSVFile = import-csv "C:\Users\me\Desktop\Distro Lists\Tests\Distros.csv"
foreach ($email in $CSVFile) {
New-DynamicDistributionGroup -Name $email.Name -Alias $email.Alias -DisplayName $email.DisplayName -PrimarySmtpAddress $email.PrimarySmtpAddress -includedrecipients "MailboxUsers"
#start-sleep -s 3
$extattr6 = $email.CustomAttribute6
$extattr3 = $email.CustomAttribute3 #($email.customattribute3).ToString()
##split each alias email so we can add each separately
$proxies = $email.EmailAddresses.split(" ")
#if ($extattr3.Length -eq 3) {
#$extattr3 = $extattr3.PadLeft(4,"0")
##-RequireSenderAuthenticationEnabled used for allowing external emails, $True=InternalOnly $False=Both
set-dynamicdistributiongroup -Identity $email.Identity -Notes $email.Notes -EmailAddresses @{add=$proxies} -RequireSenderAuthenticationEnabled $False -ManagedBy "Me" -conditionalcustomattribute3 $extattr3 -conditionalcustomattribute6 $extattr6
#set-dynamicdistributiongroup -Identity $email.Alias -Notes $email.Notes -HiddenFromAddressListsEnabled $False -ManagedBy "Me" -conditionalcustomattribute3 $extattr3 -conditionalcustomattribute6 $extattr6
#get-dynamicdistributiongroup -Identity $email.alias | select alias,name,displayname,identity
# }
}
Expected this: Recipient Filter shows customattributes separated by "-or" as they're comma delimited in the csv file
Results for most: Recipient Filter updated with what seems like the cell string, and didn't separate the values accordingly
Not sure what I'm doing wrong or what specifically it needs when setting the customattributes since only a handful got created that look like the Expected Recipient Filter.
Help?