Quick Powershell Stuff 3

This is my third installment of quick PowerShell Commands I’m using in my daily job.


During my last migration I needed to create a set of commands for changing settings in bulk on a group of users.   In this case we are going to go through the process I use for setting mailbox and personal archive mailbox quotas.  In my case the client had several levels of quotas depending on the title of the person.  That makes it hard to make an automated script to do all users from one PowerShell script. As such I simply used Excel to help me construct the Powershell commands to be run.  The PowerShell commands consisted of three parts.

get-mailbox, <user name>, and ‘| set-mailbox command <parameters>’

Here is a sample line from the spreadsheet I created (in CSV format so I can post it):

get-mailbox, Bob Smith,  | set-mailbox -IssueWarningQuota “unlimited” -ProhibitSendQuota “unlimited” -ProhibitSendReceiveQuota “unlimited” -UseDatabaseQuotaDefaults $false, “, get-mailbox “Bob Smith” | set-mailbox -IssueWarningQuota “unlimited” -ProhibitSendQuota “unlimited” -ProhibitSendReceiveQuota “unlimited” -UseDatabaseQuotaDefaults $false

This command gives Bob Smith a mailbox with no quota at all and it does not use the database defaults either.  The far right column is actually using a forumla to construct the PowerShell command that I need.  It looks something like this in reality ‘=A40&D40&B40&D40&C40’.  This allows me to construct all the parts and make one nice repeatable PowerShell command.   So column A, C, D and E are all the same with column B being reserved for the list of names.  Once I past the names in I have  a quick list of commands to run.  Simply cut and paste these into a PowerShell window in the Exchange server and you are all done.  This method saves me hours of typing depending on how many users I am working on.

The same method can be used on your personal archive quotas as well:

get-mailbox, Bob Smith, | set-mailbox -archivequota 5GB -archivewarningquota 4608MB,”,get-mailbox “Bob Smith” | set-mailbox -archivequota 5GB -archivewarningquota 4608MB

A much shorter command, but again it is a time saver.

Last, but not least is how do I verify all of this is set correctly?  Use this PowerShell Script:

$rows = “User,” + “Issue Warning,” + “Prohibit Send Quota,” + “Prohibit Send Receive Quota,” + “Use Database Defaults” Add-content c:\temp\QuotaValues.csv $rows

$userlist = import-csv c:\temp\serviceaccts.csv foreach ($line in $userlist){  $var1 = $line.user   $mb = Get-Mailbox $var1  $var2 = $mb.IssueWarningQuota  $var3 = $mb.ProhibitSendQuota  $var4 = $mb.ProhibitSendReceiveQuota  $var5 = $mb.UseDatabaseQuotaDefaults

 $rowline = “$var1,” + “$var2,” + “$var3,” + “$var4,” + “$var5”  Add-content c:\temp\QuotaValues.csv $rowline }

The above script will create a CSV file that I can use to verify that the user got the correct settings from the two scripts I ran to set mailbox and archive quotas.

Hope this latest post proves useful in your next migration.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s