A little nifty Powershell script I threw together to move users around as they get promoted to allow them to have larger inbox quotas. =)

Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host 

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010

foreach($line in get-content "\\Server\Exports\Feed.txt")
{
    if (![string]::IsNullOrWhiteSpace($line))
    {
        $recipients = $line -split [RegEx]::Escape("|")
        Try
        {
            $EID = $recipients[1].trim()
            $EmpType = $recipients[17].trim()

            $User = Get-ADUser -LDAPFilter "(sAMAccountName=$EID)" -Properties Mail
            If ($User.mail -eq $Null) 
            {
                continue
            }


            $Mb = Get-Mailbox -Identity $EID 

            if (-not $Mb)
            {
                continue
            }

            if ($EmpType -eq "DIR")
            {
                if ($Mb.Database -ne "DB04" -and $Mb.Database -ne "DBA07")
                {
                    Write-Host $EID $EmpType $Mb.Database
                    New-MoveRequest -Identity $EID -TargetDatabase "DBA04" -WhatIf
                }
            }

            if ($EmpType -eq "ELT")
            {
                if ($Mb.Database -ne "DB07")
                {
                    Write-Host $EID $EmpType $Mb.Database
                    New-MoveRequest -Identity $EID -TargetDatabase "DBA07" -WhatIf
                }
            }
        }
        catch
        {
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax