List SMTP address' based on custom attribute
All,
I am trying to get a list of all SMTP address' based on multiple values set on customattribute1. I can get this query to run:
Get-Mailbox -Filter '((CustomAttribute1 -eq ''xxxx''))'
But not this one
Get-Mailbox -Filter '((CustomAttribute1 -eq ''xxxx''))'(&(CustomAttribute1 -eq 'yyyy')'
What am I doing wrong? I have literally 2000 different possible vaules on customattribute1 that I am trying to get SMTP address' for, but I cannot seem to get it to return based on multiple values. Hope that made sense....
April 9th, 2012 2:39pm
The correct syntax for an OPATH statement would be
Get-Mailbox -Filter ((CustomAttribute1 -eq 'xxxx') -or (CustomAttribute1 -eq 'xxxx'))
if you use a -and between the different criteria, then the filter requires that all items be true to return anything, and the CustomAttributes can contain only one line, your results would be empty.
Free Windows Admin Tool Kit Click here and download it now
April 9th, 2012 3:37pm
On Mon, 9 Apr 2012 18:39:53 +0000, Rich Nixon wrote:
> I am trying to get a list of all SMTP address' based on multiple values set on customattribute1. I can get this query to run:
>
>Get-Mailbox -Filter '((CustomAttribute1 -eq ''xxxx''))'
>
>But not this one
>
>Get-Mailbox -Filter '((CustomAttribute1 -eq ''xxxx''))'(&(CustomAttribute1 -eq 'yyyy')'
>
>What am I doing wrong?
Well, that folter wouldn't work even if was a correctly formated LDIF
filter. CustomAttribute1 can never be equal to 'xxxx' AND 'yyyy'. :-)
Did you really want an "AND" condition or were you after an "OR"
condition?
In any case, the filter uses the OPATH syntax, not the LDIF syntax.
Assuming you want mailboxes that have either 'xxxx' OR 'yyyy' then
this would work:
CustomAttribute1 -eq 'xxxx' -or CustomAttribute1 -eq 'yyyy'
>I have literally 2000 different possible vaules on customattribute1 that I am trying to get SMTP address' for, but I cannot seem to get it to return based on multiple values. Hope that made sense....
Depending on the complexity of the combinations you might find the
slower, but more flexible, Powershell stuff a better fit.
$vals = 'a','b','c','d','e','f'
get-mailbox | foreach {
if ($vals -contains $_.CustomAttribute1)
{
do something
}
}
or maybe a 'switch':
get-mailbox | foreach {
switch ($_.CustomeAttribute1)
{
'xxxx' {blah;break}
'yyyy' {foobar;break}
'zzzz' {somethingelse;break}
default {somethingreallydifferent;break}
}
}
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
April 9th, 2012 5:40pm
Hi Rich,
Any updates?Frank Wang
TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
April 10th, 2012 11:29pm