Return the Smallest Mailbox Database

Locates the smallest mailbox database (in terms of size) for automatic provisioning process. The script retrieves a collection of mailbox databases, finds the size of each databas

 
 
 
 
 
2 Star
(2)
Add to favorites
Exchange
8/10/2009
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Works fine on the local server.
    2 Posts | Last post December 11, 2009
    • Works fine when run locally.  I'm working on somethign that might allow this to be useful in an enterprise.  Currently you'd have to log on to each of your servers locally to have this script be valid.  Fine for a single server environment where admin is done on the server.  And useful as a means for determining smallest db size per server.  I took out the sort -property lenght ) [0] to make it return all of my db sizes per server. 
    • would I be able to use this as a variable, like $a? and then call it from within my script so the mailboxes are moved to the smallest DB? and then how can I have another var. that excludes a DB based on size?
      
      # ==============================================================================================
      #
      # NAME: SprayMoves.ps1
      #
      # DESCRIPTION:
      #   Given an input file with a list of SMTP addresses this script will
      #   move those mailboxes to a specified server across all (or part)
      #   of the databases on the server.
      #
      # EXAMPLES:
      #
      #   > .\SprayMoves mblist.txt
      #
      # VERSION: 1.0
      #
      # VERSION HISTORY:
      #   1.0: Phil Braniff - Modification to Inital script provided from Doug Lawty(msft).
      #
      
      param(
        [string] $inputFile = (Read-Host -Prompt "Input file" )
      )
      $AdminSessionADSettings.ViewEntireForest = $true;
      # Check to see if the provided file name exists.
      if ( Test-Path $inputFile ) {
        $addressList = Get-Content $inputFile;
        # The file can either have a header row or not. If it does, remove it.
        if ( ! ($addressList[0].Contains("@")) ) { $addressList = $addressList[1..($addressList.Length - 1)]; }
      } else {
        Write-Host "Specified address list does not exist!" -ForegroundColor Red
        exit;
      }
      $serverName = (Read-Host -Prompt "Supply the destination Server name for these moves:" )
      $database = "\SG1\1MBX1","\SG2\2MBX1","\SG3\3MBX1","\SG4\4MBX1","\SG5\5MBX1","\SG6\6MBX1","\SG7\7MBX1"
      $i = 0
      foreach ( $address in $addressList ) {
        $db = $($serverName) ($database[$i])
        Move-Mailbox -id $address.trim() -targetdatabase $db -BadItemLimit 50 -PreserveMailboxSizeLimit:$true -Confirm:$False -whatif;
        $i = $i 1
        if ($i -eq $database.length)
        {
           $i = 0
        }
      }