I am trying to do something very simple in Exchange 2019 powershell, but for the life of me I cannot seem to get my head around a simple variable placement. The issue has nothing to do with Exchange, just pure PS.
I need to execute the cmdlet
New-AddressList "XX Users" -RecipientFilter {((CustomAttribute2 -eq "XX") -and (RecipientType -eq 'UserMailbox'))}
which is fine, but I want to replace "XX Users" and "XX" with variables.
I can replace "XX Users" by saying something like
$var1 = "XX Users" (this actually works)
$var2 = "XX" (does not work)
so I get
New-AddressList $var1 -RecipientFilter {((CustomAttribute2 -eq $var2) -and (RecipientType -eq 'UserMailbox'))}
for the life of me that $var2
does not insert the correct value for the -eq
. I have tried numerous combinations, including using single quote, double quote, where object, moving braces around and I have gotten nowhere. It either takes it as literal or null.