Powershell - Address list matching a name which contains an asterisk
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.
January 31st, 2012 2:48pm

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
Free Windows Admin Tool Kit Click here and download it now
January 31st, 2012 10:08pm

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
February 1st, 2012 2:29am

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 '`*'))}
Free Windows Admin Tool Kit Click here and download it now
February 1st, 2012 9:52am

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
February 1st, 2012 10:06pm

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
Free Windows Admin Tool Kit Click here and download it now
February 2nd, 2012 1:33am

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
February 2nd, 2012 9:26am

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
Free Windows Admin Tool Kit Click here and download it now
February 7th, 2012 1:42am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics