Office 365 Scripting RRS feed

  • Question

  • I am trying to add Mail-Contacts and Dynamic Distribution Groups to Office 365 Online. I am able to add both but for some reason when I search the members of the DDG the members do not appear. I am using the following code in my loop to add the DDG:

    $myVal = 4

    New-DynamicDistributionGroup -name $item.DistributionGroupName -RecipientFilter "{(ExtensionCustomAttribute1 -eq '${myVal}')}" -Alias $item.Alias -DisplayName $item.DisplayName


    The following is the code to add the MailContact:

    $ExtensionCustomAttribute = "2,4,5,6,99996,99999"

    new-MailContact -alias $item.alias -name $item.name -ExternalEmailAddress $item.ExternalEmailAddress | Out-Null

    set-mailcontact -identity $item.name -ExtensionCustomAttribute1 $ExtensionCustomAttribute


    I then try to verify the membership using the following:

    $fte = Get-DynamicDistributionGroup "cawg_all"

    Get-Recipient -RecipientPreviewFilter $FTE.RecipientFilter

    When I look at the individual items the DDG I see the correct Recipient Filter and when I look at the Mail-Contact I see the items above in the extensionCustomAttribute1 property.

    Any help would be appreciated.

    • Moved by Bill_Stewart Friday, August 14, 2015 6:20 PM This is not Office 365 online support forum
    Tuesday, June 16, 2015 12:50 PM

All replies

  • Hi Steve,

    Hope you have the permissions required to run the Get-Recipient cmdlet.

    You must be referring to View members of a dynamic distribution group for previewing the result of the DDG.

    Basically the cmdlets that you are running doesn't get the values from the DDG cache, but actually is extracting the FilterQuery and using that query to run across the live DC using Get-Recipient.

    Run this directly to see if you have the required results. Also search scope of AD should be set to :Forestwide

    Get-Recipient -RecipientPreviewFilter "{(ExtensionCustomAttribute1 -eq '${myVal}')}" -IgnoreDefaultScope

    Hence slight variation in the output is expected, more over if you have OUs scope mentioned in the DDG then the result would vary a lot.

    DDG would list out members from the OU and SubOUs of the group's OU location. But the Get-Recipient cmdlet would not limit the result to the OU.

    "The RecipientContainer parameter filters the recipients used to build the dynamic distribution group based on their location in Active Directory. The value of the RecipientContainer parameter can be the canonical name of an organizational unit (OU) or a domain. If you don't specify a value for the RecipientContainer parameter, the cmdlet will default to use the local container. This location is specified by using the OrganizationalUnit parameter."

    "The IgnoreDefaultScope parameter instructs the command to ignore the default recipient scope setting for the Exchange Management Shell session and use the entire forest as the scope. This allows the command to access Active Directory objects that aren't currently in the default scope. Using the IgnoreDefaultScope parameter introduces the following restrictions:

    • You can't use the DomainController parameter. The command uses an appropriate global catalog server automatically.

    • You can only use the DN for the Identity parameter. Other forms of identification, such as alias or GUID, aren't accepted.

    • You can't use the OrganizationalUnit and Identity parameters together.

    • You can't use the Credential parameter."



    Please“Vote As Helpful” if you find my contribution useful or “MarkAs Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

    • Edited by Satyajit321 Friday, June 19, 2015 8:16 AM
    • Proposed as answer by Satyajit321 Tuesday, December 15, 2015 10:52 AM
    Friday, June 19, 2015 8:14 AM