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 *