Solved

need assistance modifying an exchange posh script

Posted on 2011-09-13
14
703 Views
Last Modified: 2012-05-12
we run the attached script daily to go through and enable the online archive for any e2010 accounts that currently do not have the archive enabled. however, we have a few high priority VP's and executives that require a different quota setting. is there a way to add in an "-exclude" line to this script to exclude specific users from being impacted by this?

many thanks!

S.
$Mailboxes = Get-Mailbox -Database "Mailbox Database Server-Mailbox01" -OrganizationalUnit "OU=Newcorp,OU=Users,,DC=Mydomain,DC=com" | Where-Object { -Not $_.Archive }
$Mailboxes | ForEach-Object {
  $_ | Enable-Mailbox -Archive -ArchiveDatabase "Archive Database DC1-ARCHIVE"
  $_ | Set-Mailbox -ArchiveQuota 10GB -ArchiveWarningQuota 9096MB
}

Open in new window

0
Comment
Question by:siber1
  • 7
  • 7
14 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36535878
Set one of the CustomAttributes in each record you want to exclude and then use:-

$MailBoxes = get-mailbox | where {$_.CustomAttribute5 -ne "VIP"} -database.......
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36535917
By way of an explination....

The above of course assumes that all your "VIP's" Have the CustomAttribute5 field set to the string "VIP"
0
 

Author Comment

by:siber1
ID: 36537519
Hi Neilsr, when i run this in the lab i get the following error:

Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Enable-Mailbox], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Enable-Mailbox

Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Set-Mailbox], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-Mailbox

Where-Object : A parameter cannot be found that matches parameter name 'Database'.
At C:\scripts\en-employeeArchive.ps1:15 char:85
+ $Mailboxes = Get-Mailbox | where {$_.CustomAttribute15 -ne "ArchiveQuota"} -Database <<<<  "Mailbox Database XX-MDB0
3" -OrganizationalUnit "OU=temp,DC=domain,DC=com" | Where-Object { -Not $_.Archive }
    + CategoryInfo          : InvalidArgument: (:) [Where-Object], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.WhereObjectCommand
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36537737
Can you post your whole script as modified please.
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 500 total points
ID: 36537751
Ah my bad, i see. I was not thinking well enough.....


$Mailboxes = Get-Mailbox -Database "Mailbox Database Server-Mailbox01" -OrganizationalUnit "OU=Newcorp,OU=Users,,DC=Mydomain,DC=com" | where {$_.CustomAttribute5 -ne "VIP"} | Where-Object { -Not $_.Archive }  

I think!

I dont have access to exchange right now but I think thats right.....
0
 

Author Comment

by:siber1
ID: 36538009
Hi Neilsr, i just re-tested in the Lab and that cleared the error, however the script still hits all VP accounts even though we specified "where {$_.CustomAttribute5 -ne "VIP"} " in the script.

and reverts them back to to policy settings.

full script is attached.

thx
$Mailboxes = Get-Mailbox -Database "Mailbox Database xx-MDB01" -OrganizationalUnit "OU=temp,DC=mydomain,DC=com" | where {$_.CustomAttribute15 -ne "ArchiveQuota"} | Where-Object { -Not $_.Archive }
$Mailboxes | ForEach-Object {
  $_ | Enable-Mailbox -Archive -ArchiveDatabase "Archive Database xx-ARCHIVEDB"
  $_ | Set-Mailbox -ArchiveQuota 8GB -ArchiveWarningQuota 7096MB
}

Open in new window

0
 

Author Comment

by:siber1
ID: 36538013
also, i have added the "VIP" field in custom attribute. still it hits those accounts and doesnt exclude.
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:siber1
ID: 36540342
Hi Neilsr, do you have any update on this? when i run what you suggested the script still doesnt exclude the VP accounts?
any suggestions would be much appreciated!!

S.
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36541971
Your script says......

 $Mailboxes = Get-Mailbox -Database "Mailbox Database xx-MDB01" -OrganizationalUnit "OU=temp,DC=mydomain,DC=com" | where {$_.CustomAttribute15 -ne "ArchiveQuota"} | Where-Object { -Not $_.Archive }
$Mailboxes | ForEach-Object {
  $_ | Enable-Mailbox -Archive -ArchiveDatabase "Archive Database xx-ARCHIVEDB"
  $_ | Set-Mailbox -ArchiveQuota 8GB -ArchiveWarningQuota 7096MB
}

and NOT what i suguested

0
 

Author Comment

by:siber1
ID: 36544903
I just used the word "ArchiveQuota" as the value .. rather than "VIP" ..  it shouldn't matter right?
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36544996
ok thats fine. And of course you have set the attribute to that value on the users?
0
 

Author Comment

by:siber1
ID: 36545973
yes
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 36546167
Is the output from

Get-Mailbox -Database "Mailbox Database xx-MDB01" -OrganizationalUnit "OU=temp,DC=mydomain,DC=com" | where {$_.CustomAttribute15 -ne "ArchiveQuota"} | Where-Object { -Not $_.Archive }

The list you would expect? The syntax is correct, i just ran exactly that on my lab server and it does exactly what is expected.

0
 

Author Closing Comment

by:siber1
ID: 36546272
thx again! just re-tested and it works perfectly.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Outlook importing calendar entries 6 66
exchange, 2 21
Password change 3 25
GPO help required 12 42
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now