Set custom attribute with exception
Hello,
Under Exchange 2007 I run the below shell command to set the custom attribute 2 to exchange
Get-Mailbox -ResultSize Unlimited | Set-Mailbox -CustomAttribute2 "EXCHANGE"
I need to apply that command to all mailbox except those in the below OU
« company.intra/company/Old/Users/ »
and
« uk.company.intra/Main/Old Users »
Is there any possibility to combine those exceptions with the above shell command??
Thanks to all in advance for your input.
Graig
April 26th, 2010 9:46pm
One way:
Get-Mailbox -ResultSize Unlimited |? {$_.distinguishedname -notmatch "ou=users,ou=old,ou=company|ou=oldusers,ou=main"} | Set-Mailbox -CustomAttribute2 "EXCHANGE"
Free Windows Admin Tool Kit Click here and download it now
April 26th, 2010 10:00pm
Another way:
Get-Mailbox -ResultSize Unlimited |? {
$_.organizationalunit -ne "company.intra/company/Old/Users" -and $_.organizationalunit -ne "uk.company.intra/Main/Old Users "} |
Set-Mailbox -CustomAttribute2 "EXCHANGE"
April 26th, 2010 10:32pm
Hello mjolinor,
I am sorry. In fact I run that command:
Get-Mailbox -ResultSize Unlimited | where {$_.CustomAttribute2 -like ""} | Set-Mailbox -CustomAttribute2 "EXCHANGE"
And I would need to REMOVE the CustomAttribute2 which is "EXCHANGE" for the 2 below OU :
« company.intra/company/Old/Users/ »
and
« uk.company.intra/Main/Old Users »
Sorry about that I got confused myself.. Can you help me out with that one then?
Thanks for your prior input (It will help me for some other stuff :-D)
Graig
Free Windows Admin Tool Kit Click here and download it now
April 27th, 2010 10:32am
Get-Mailbox -ResultSize Unlimited -organizationalunit "company.intra/company/Old/Users" |
Set-Mailbox -CustomAttribute2 ""
Get-Mailbox -ResultSize Unlimited -organizationalunit "uk.company.intra/Main/Old Users" |
Set-Mailbox -CustomAttribute2 ""
April 27th, 2010 3:24pm
Thanks mjolinor,
Do you know any way to combine the 3 commands??
Get-Mailbox -ResultSize Unlimited | where {$_.CustomAttribute2 -like ""} | Set-Mailbox -CustomAttribute2 "EXCHANGE"
Get-Mailbox -ResultSize Unlimited -organizationalunit "company.intra/company/Old/Users" | Set-Mailbox -CustomAttribute2 ""
Get-Mailbox -ResultSize Unlimited -organizationalunit "uk.company.intra/Main/Old Users" | Set-Mailbox -CustomAttribute2 ""
Because I need to activate that CustomAttribute2for any user and remove that CustomAttribute2 for users in the two OUs I gave.
Free Windows Admin Tool Kit Click here and download it now
April 27th, 2010 5:27pm
get-mailbox -resultsize unlimited |%{
if ($_.organizationalunit -eq "uk.company.intra/Main/Old Users" -or $_.organizationalunit -eq "company.intra/company/Old/Users") {set-mailbox $_ -CustomAttribute2 ""}
else {Set-Mailbox $_ -CustomAttribute2 "Exchange"}
}
April 27th, 2010 6:16pm
You may also use admodify2.1
Free Windows Admin Tool Kit Click here and download it now
April 27th, 2010 6:21pm
Thanks Mjolonor it worked perfectly well.
Just last thing, I wanna use the CustomAttribute10 for the user's country based on a specific organizationalunit :
I wrote why I though it would work but I do not have a test environnement, so could you please tell me if the command I wrote is correct?
get-mailbox -resultsize unlimited |%{
if ($_.organizationalunit -eq "uk.company.intra/Main/Old Users" -or $_.organizationalunit -eq "company.intra/company/Old/Users") {set-mailbox $_ -CustomAttribute10 ""}
else
{$_.organizationalunit -eq "company.intra/Barcelona*" Set-Mailbox $_ -CustomAttribute10 "BARCELONA"}}
April 29th, 2010 12:54pm
Thanks Mjolonor it worked perfectly well.
Just last thing, I wanna use the CustomAttribute10 for the user's country based on a specific organizationalunit :
I wrote why I though it would work but I do not have a test environnement, so could you please tell me if the command I wrote is correct?
get-mailbox -resultsize unlimited |%{
if ($_.organizationalunit -eq "uk.company.intra/Main/Old Users" -or $_.organizationalunit -eq "company.intra/company/Old/Users") {set-mailbox $_ -CustomAttribute10 ""}
else
{$_.organizationalunit -eq "company.intra/Barcelona*" Set-Mailbox $_ -CustomAttribute10 "BARCELONA"}}
Hi,
No its a wrong script
else
{$_.organizationalunit -eq "company.intra/Barcelona*" Set-Mailbox $_ -CustomAttribute10 "BARCELONA"}}
Above line wont run anyway.
convert it to
else if($_.organizationalunit -like "company.intra/Barcelona*")
{ Set-Mailbox $_ -CustomAttribute10 "BARCELONA"}}
hopefully it will work. I have put -like because u used * in the end of OU name.
Also Your script will only deal with 3 OUs and it wont do anything to any other mailbox excetp those 3 mentioned OUs. IF this is what you want then its ok.
Regards,
Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM)
www.HostingController.com
Free Windows Admin Tool Kit Click here and download it now
April 29th, 2010 1:29pm
There's a couple of things I think you'll need to change.
You need to use an if or elseif on the Barcelona bit, and -eq is an exact match operator (it doesn't understand wildcards), so you'll want to use the -like operator instead.
get-mailbox -resultsize unlimited |%{
if ($_.organizationalunit -eq "uk.company.intra/Main/Old Users" -or $_.organizationalunit -eq "company.intra/company/Old/Users") {set-mailbox $_ -CustomAttribute10 ""}
elseif ($_.organizationalunit -like "company.intra/Barcelona*"){ Set-Mailbox $_ -CustomAttribute10 "BARCELONA"}
}
April 29th, 2010 1:40pm