Thank you very much! The first one you suggested did the trick.
If I may ask a follow up question, I’m trying to create another line of script to create an AddressList but am getting stuck when having to use a system value and a variable. I’ve had a read through the link you provided which I believe says I need to enclose the filter with single quotation marks instead of double. I’m sure it’s probably just a case of a quotation or bracket in the wrong place, but I can’t work it out.
I’ve listed some of my attempts, along with the errors, below. (The actual line of code I have contains more filter options, but I’ve simplified it below as I’m sure once the below is working I’ll be able to expand it accordingly.)
This first attempt seems to ignore $null and just shows it as an empty space in the error:
New-AddressList -Name "All Rooms - $sitecode" -RecipientFilter "'Alias -ne '$null' -and (CustomAttribute7 -like '$sitecode*')"
Cannot bind parameter 'RecipientFilter' to the target. Exception setting "RecipientFilter": "Invalid filter syntax. For a description of the filter parameter syntax see the command help.
"'Alias -ne '' -and (CustomAttribute7 -like 'ABC*')" at position 1."
I then tried to remove the double quotation marks altogether, but again no luck:
New-AddressList -Name "All Rooms - $sitecode" -RecipientFilter 'Alias -ne $null -and (CustomAttribute7 -like '$sitecode*')'
A positional parameter cannot be found that accepts argument 'ABC*)'.
I’ve also tried using double quotes around the variable where I’m now using single quote marks around the whole filter. Although it doesn’t error, it then (again) uses the variable name rather than variable value in the result:
New-AddressList -Name "All Rooms - $sitecode" -RecipientFilter 'Alias -ne $null -and (CustomAttribute7 -like "$sitecode*")'
Name DisplayName RecipientFilter
---- ----------- ---------------
All Rooms - ABC All Rooms - ABC ((Alias -ne $null) -and (CustomAttribute7 -like '$sitecode*'))
I think I’m close, but any help getting this working properly would be greatly appreciated.
Just to give the complete picture of where I’m trying to get to, the below is the full PowerShell line I’m using when not using a variable and just entering the value in statically:
New-AddressList -Name "All Rooms - ABC" -RecipientFilter {(Alias -ne $null) -and (CustomAttribute5 -like 'ABC*') -and (RecipientDisplayType -eq 'ConferenceRoomMailbox') -or (RecipientDisplayType -eq 'SyncedConferenceRoomMailbox')}
Name DisplayName RecipientFilter
---- ----------- ---------------
All Rooms - ABC All Rooms - ABC ((((((Alias -ne $null) -and (CustomAttribute5 -like 'ABC*'))) -and (RecipientDisplayType -eq 'ConferenceRoomMailbox'))) -or (RecipientDisplayType -eq
'SyncedConferenceRoomMailbox'))