none
Powershell - Address list matching a name which contains an asterisk RRS feed

  • Question

  • I'm running into a problem trying to do powershell scripting.  I've searched and I've been unable to find the answer so far.  Basically I'm trying to create a new address list and have it match by the name of some of our distribution groups.  The problem is that a lot of our distribution groups start with an asterisk, which is also a wildcard.  Is there any way to match those names?  Basically I want to include an actual asterisk in the string to match on and not have it interpreted as a wildcard.

     

    Tuesday, January 31, 2012 7:42 PM

Answers

  • Hello,

     

    If you want to filter name start with asterisk, you can use $Name –like ‘`**’, but this seems not work when you used like this:

     

    New-AddressList Test -RecipientFilter {((((((((((RecipientType -eq 'MailUniversalDistributionGroup') -or (RecipientType -eq 'MailUniversalSecurityGroup'))) -or (RecipientType -eq 'MailNonUniversalGroup'))) -or (RecipientType -eq 'DynamicDistributionGroup'))) -and (ObjectCategory -like 'group'))) -and (Name -like '`**'))}

     

    If you want to create one addresslist like that, here is a workaround:

     

    <1> Get all groups which name start with asterisk (use $_Name[0] –eq “*” or $_Name –like ‘`**’)

     

    $Groups=get-distributiongroup | where{$_.Name –like ‘`**’}

     

    <2> Change the customattribute1 for all the groups whose name is start with asterisk (this example I add test to customattribute1):

     

    $Groups| foreach{ set-distributiongroup –identity $_.identity –CustomAttribute1 test}

     

    <3> Create one addresslist which fit your requirements and CustomAttribute1 is test:

     

    New-AddressList Test -RecipientFilter {((((((((((RecipientType -eq 'MailUniversalDistributionGroup') -or (RecipientType -eq 'MailUniversalSecurityGroup'))) -or (RecipientType -eq 'MailNonUniversalGroup'))) -or (RecipientType -eq 'DynamicDistributionGroup'))) -and (ObjectCategory -like 'group'))) -and (customAttribute1 -eq 'test'))}

     

    Thanks,

     

    Evan Liu

     

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tngfb@microsoft.com  


    Evan Liu

    TechNet Community Support

    Thursday, February 2, 2012 6:26 AM
    Moderator

All replies

  • On Tue, 31 Jan 2012 19:42:09 +0000, Schwagro wrote:
     
    >
    >
    >I'm running into a problem trying to do powershell scripting. I've searched and I've been unable to find the answer so far. Basically I'm trying to create a new address list and have it match by the name of some of our distribution groups. The problem is that a lot of our distribution groups start with an asterisk, which is also a wildcard. Is there any way to match those names? Basically I want to include an actual asterisk in the string to match on and not have it interpreted as a wildcard.
     
    Escape the asterisk. E.g. "`*"
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Wednesday, February 1, 2012 3:03 AM
  • Hello,

     

    Since you have distribution groups’ name start with an asterisk, you can use this to filter all the groups start with asterisk:

     

    $_.Name[0]  -eq “*”  ($_.Name is the Name of distribution group)

     

    If you want to filter all the groups that name included asterisk, you can use this:

     

    $_.Name.contains(“*”)

     

    Thanks,

     

    Evan Liu

     

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tngfb@microsoft.com  


    Evan Liu

    TechNet Community Support

    Wednesday, February 1, 2012 7:23 AM
    Moderator
  • I tried this and it doesn't seem to work correctly.  The command takes, but it doesn't return any results in a preview.  Here is my full command, i know everything is working, except for the last part.

     New-AddressList Test -RecipientFilter {((((((((((RecipientType -eq 'MailUniversalDistributionGroup') -or (RecipientType -eq 'MailUniversalSecurityGroup'))) -or (RecipientType -eq 'MailNonUniversalGroup'))) -or (RecipientType -eq 'DynamicDistributionGroup'))) -and (ObjectCategory -like 'group'))) -and (Name -like '`*'))} 

     

    Wednesday, February 1, 2012 2:45 PM
  • On Wed, 1 Feb 2012 14:45:34 +0000, Schwagro wrote:
     
    >I tried this and it doesn't seem to work correctly. The command takes, but it doesn't return any results in a preview. Here is my full command, i know everything is working, except for the last part.
    >
    > New-AddressList Test -RecipientFilter {((((((((((RecipientType -eq 'MailUniversalDistributionGroup') -or (RecipientType -eq 'MailUniversalSecurityGroup'))) -or (RecipientType -eq 'MailNonUniversalGroup'))) -or (RecipientType -eq 'DynamicDistributionGroup'))) -and (ObjectCategory -like 'group'))) -and (Name -like '`*'))}
     
    Well, unless the "Name" value is exactly one asterisk then I'd say
    it's working properly. If your intention is to find values of 'Name'
    that begin with '*' then '`**' would be the pattern to use.
     
    $n = "*ab"
     
    $n -like '`*'
    False
     
    $n -like '`*b'
    True
     
    $n -like '`**'
    True
     
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Thursday, February 2, 2012 3:00 AM
  • Hello,

     

    If you want to filter name start with asterisk, you can use $Name –like ‘`**’, but this seems not work when you used like this:

     

    New-AddressList Test -RecipientFilter {((((((((((RecipientType -eq 'MailUniversalDistributionGroup') -or (RecipientType -eq 'MailUniversalSecurityGroup'))) -or (RecipientType -eq 'MailNonUniversalGroup'))) -or (RecipientType -eq 'DynamicDistributionGroup'))) -and (ObjectCategory -like 'group'))) -and (Name -like '`**'))}

     

    If you want to create one addresslist like that, here is a workaround:

     

    <1> Get all groups which name start with asterisk (use $_Name[0] –eq “*” or $_Name –like ‘`**’)

     

    $Groups=get-distributiongroup | where{$_.Name –like ‘`**’}

     

    <2> Change the customattribute1 for all the groups whose name is start with asterisk (this example I add test to customattribute1):

     

    $Groups| foreach{ set-distributiongroup –identity $_.identity –CustomAttribute1 test}

     

    <3> Create one addresslist which fit your requirements and CustomAttribute1 is test:

     

    New-AddressList Test -RecipientFilter {((((((((((RecipientType -eq 'MailUniversalDistributionGroup') -or (RecipientType -eq 'MailUniversalSecurityGroup'))) -or (RecipientType -eq 'MailNonUniversalGroup'))) -or (RecipientType -eq 'DynamicDistributionGroup'))) -and (ObjectCategory -like 'group'))) -and (customAttribute1 -eq 'test'))}

     

    Thanks,

     

    Evan Liu

     

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tngfb@microsoft.com  


    Evan Liu

    TechNet Community Support

    Thursday, February 2, 2012 6:26 AM
    Moderator
  • Hi,

    Any updates on this issue?

    Thanks,

    Evan Liu

     

    TechNet Subscriber Supportin forum

    If you have any feedback on our support, please contacttngfb@microsoft.com 


    Evan Liu

    TechNet Community Support

    Tuesday, February 7, 2012 6:38 AM
    Moderator