The Exchange 2007 Wiki

Bulk Change Mailbox Quotas

Description

This script makes it possible to easily change the quotas on all your mailboxes.

Usage


Copy the script code below into a text file and name it ChangeMailboxQuota.msh. In the Exchange Management Shell navigate to the directory in which you saved the script and run the command below:

ChangeMailboxQuota [-WarningQuota [<>]] [-SendQuota [<>]] [-SendRecvQuota [<>]]

Sample Script


param(
        $warningQuota = $(read-host "Issue warning quota(KB)"),
        $sendQuota = $(read-host "Prohibit send quota(KB)"),
        $sendrecvQuota = $(read-host "Prohibit send and receive quota(KB)")
)

function usage {
 write-host "Usage: ChangeMailboxQuota [-WarningQuota [<>]] [-SendQuota [<>]] [-SendRecvQuota [<>]]"
}

## Parse paramaters (specified as "-paramname paramvalue")
for($i = 0; $i -lt $args.Length; $i++)
{
    switch ($args[$i])
   {
        "-WarningQuota"
           {
                       if ($args[$i+1]) 
                       {
                            $warningQuota = $args[$i+1]
                            $i++
                       }
                       else
                      {
                            write-host "Error: -WarningQuota requires an argument"
                            usage
                            return
                       }
   
                      continue 
             }

         "-SendQuota"
           {
                       if ($args[$i+1])
                       {
                             $sendQuota = $args[$i+1]
                             $i++
                       }
                       else
                       {
                             write-host "Error: -SendQuota requires an argument"  
                             usage

                             return
                        }

                  

                     continue
          }

        "-SendrecvQuota"
         {
                     if ($args[$i+1])
                     {
                           $sendrecvQuota = $args[$i+1]
                           $i++
                     }
                     else
                     {
                           write-host "Error: -SendRecvQuota requires an argument"
                           usage
                           return
                     }

                 continue 
         }

        default 
        { 
                  write-host "Error: bad argument" $args[$i]
                  usage
                  return
        }
   }
}

$mailboxes = get-mailbox
if ($mailboxes -eq $null)
{
     write-host "No existing mailbox..."
    return
}

foreach($mailbox in $mailboxes)
{
      write-host "Change quota of mailbox: " $mailbox.Name
     if($warningQuota)

     {
            $newWarningQuota = $warningQuota
            write-host "  Changing issue warning quota from" $mailbox.IssueWarningQuota "to" $warningQuota
      }

     else

     {
           $newWarningQuota = $mailbox.IssueWarningQuota
     }

   if($sendQuota)

  {
        $newSendQuota = $sendQuota
        write-host "  Changing prohibit send quota from" $mailbox.ProhibitSendQuota "to"        $sendQuota
   }

   else

  {
        $newSendQuota = $mailbox.ProhibitSendQuota
   }

   if($sendrecvQuota)

   {
           $newSendrecvQuota = $sendrecvQuota
          write-host "  Changing prohibit send and receive quota from"  $mailbox.ProhibitSendReceiveQuota "to" $sendrecvQuota
   }

   else

  {
          $newSendrecvQuota = $mailbox.ProhibitSendReceiveQuota
   }

 

set-mailbox -identity $mailbox -IssueWarningQuota $newWarningQuota -ProhibitSendQuota $newSendrecvQuota -ProhibitSendReceiveQuota $newSendrecvQuota

}

 

 

Disclaimer: The sample scripts are meant to serve as examples and may need modifications before they will work in your environment. The authors of the script are not responsible for any negative outcome that may result from using them. 

Site

Changes
Index
Search

 

User

 

Log In
Register

 
 

Last Modified 8/3/06 5:35 PM