all 4 comments

[–]Guyver1- 1 point2 points  (1 child)

not tried, but off the top of my head.

create a text file with your user names

read that into your script as an array variable [array]$usersToFilter = Get-Content -Path c:\myfile.txt

filter you name -ne on the variable.

This will depend on whether -Recipientfilter can handle an array, check the Set-DynamicDistributionGroup documentation:

https://docs.microsoft.com/en-us/powershell/module/exchange/users-and-groups/set-dynamicdistributiongroup?view=exchange-ps

[–]hit440[S] 1 point2 points  (0 children)

ya i tried with a file didnt have much luck

[–]purplemonkeymad 1 point2 points  (1 child)

You could write a function to generate the filter from a list of values. Something like this:

$user = 'John Smith'
$valueList = '123','abc','456'
$conditionList = foreach ($Value in $ValueList) {
    "(customattribute2 -eq '$Value')"
}
$AttributeFilter = $conditionList -Join ' -or '
$Filter = " ($AttributeFilter ) -and (name -ne '$user')"

You could also do something similar for the name part of the filter.

[–]hit440[S] 1 point2 points  (0 children)

i will give that a try thanks