Author Posts

April 4, 2016 at 7:29 am

I'm trying to make a variable from a number of the variables, so that I can create a global address list in Exchange. Here's a list of the variables I'm using:

$CompanyName="Test 1"
$ADGroupType1="Broadcast Group"
$TenantOURootPath="ou=Tenants,DC=exchange14,DC=local"
$MSPMailTargetOU=("OU=" + $CompanyName + "," + $TenantOURootPath)
$Memberof="CN=" + $CompanyName + " " + $ADGroupType1 + "," +$MSPMailTargetOU

If I check any of the variables above by just typing the variable name, the values look as I would want them, however when I run the following command:

[PS] C:\Tools\CopyAD>New-GlobalAddressList ($CompanyName + " Global Address List") -RecipientFilter {(memberofgroup -eq
$memberof)}

My new global address list is created but with a recipientfilter value of "-not(MemberOfGroup -ne $null)". I'm confused (not to say annoyed!). Is what I'm trying to do, given the amount of variables I'm trying to join up, even possible?

Thanks in advance for any advice you may have.

April 6, 2016 at 9:49 am

I don't usually concatenate at all. Use double quotes and subexpressions.

$final = "This is a $piece of $($object.property)."

Variables can go right into double quotes. No need to concatenate.

August 3, 2016 at 11:20 am

I've got a very similar problem. I work for a service provider that creates new customers regularly, so I'm trying to write a script to help automate this. I'm building an email address policy based on certain variables which are entered by the administrator using read-host. The variables are being set ok, so what I end up with is this:

$OUName=CustomerOUName
$AddressFormat=%g (or whatever the desired format is)
$EmailDomain=domain.com (again, whatever it is for any given customer)
$GroupPath=GroupName

Now using the above variables, this works:
New-EmailAddressPolicy -name ($OUName + ' Policy') -EnabledEmailAddressTemplates ('SMTP:' + $AddressFormat + '@' + $EmailDomain) -RecipientFilter ("MemberOfGroup -eq '$GroupPath'")

But later on when I'm building global address lists etc, I need to add in other bits, such as:

("MemberOfGroup -eq '$GroupPath'" -and ((Alias -ne $null) -and ((RecipientDisplayType -eq 'ConferenceRoomMailbox') -or (RecipientDisplayType -eq 'SyncedConferenceRoomMailbox')))

For the life of me I cannot make this or any other variation that I'm aware of work so that I can build criteria for the object I'm creating. How would I do this using variables and multiple factors with the -RecipientFilter?

Many thanks!

  • This reply was modified 2 years, 2 months ago by  Tony Bennett.

August 3, 2016 at 12:42 pm

I was in such a rush to get this posted, I didn't realise that the original post was mine! (not entirely sure why I haven't answered this previously to say that my script had moved on though). So forgetting the first problem, it's moved on to the later comment I've made on the issue. Thanks.

August 3, 2016 at 12:55 pm

"(MemberOfGroup -eq '$GroupPath' -and ((Alias -ne `$null) -and ((RecipientDisplayType -eq 'ConferenceRoomMailbox') -or (RecipientDisplayType -eq 'SyncedConferenceRoomMailbox')))"

When it was just like this:

"MemberOfGroup -eq '$GroupPath'"

Say $GroupPath equals CN=MyGroup,OU=MyOU,DC=domain,DC=com, what you are passing the cmdlet is:

"MemberOfGroup -eq 'CN=MyGroup,OU=MyOU,DC=domain,DC=com'"

You are passing it a string with some simple comparisons. The more complex one you posted isn't surrounded by quotes and if you ran it by itself it would error out. You have to build the whole thing as a string. And if it is a double quoted string, $null will expand out to the actual null value unless you escape the $ before it.

  • This reply was modified 2 years, 2 months ago by  Craig Duff.