This function retrieves the total size (in GB) of mailbox databases in Exchange Organization. There is an optional parameter to filter databases by part of name. When you specify a value for the Name attribute and no databases could be found, it retrieves 0.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Function Get-MailboxDatabaseTotalSize { param ([Parameter(Mandatory=$false, ValueFromPipeline=$false)][string]$DBPartName) $Databases = Get-MailboxDatabase -Status | Where-Object {$_.Name -ilike '*'+$DBPartName+'*'} foreach($Database in $Databases) { $RawDBSize = $Database.DatabaseSize $CounterDBTotalSize = $RawDBSize + $CounterDBTotalSize } try { $CounterDBTotalSize = "{0:n2}" -f ($CounterDBTotalSize.ToBytes() / 1GB) } catch { Write-Host "0" } Return $CounterDBTotalSize } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# Mailbox $Mailbox = "Mail@domain.com" # Exchange server contains tracking logs - by default CAS $Serv = "exch01.domain.com" $Now = Get-Date $DayBack = (7,6,5,4,3,2,1) Write-Host $Mailbox" report" Write-Host "====================" foreach ($DayIndex in $DayBack) { $CT = $Now.AddDays(-$DayIndex) $CTDayOfWeek = (Get-Date($CT)).DayOfWeek $CTToDisplay = Get-Date($CT) -Format dd.MM.yyyy $CT = Get-Date($CT) -Format MM/dd/yyyy $CTStart = $CT+" 0:00:00AM" $CTEnd = $CT+" 23:59:59PM" $MailCount = (Get-MessageTrackingLog -Recipients $Mailbox -server $Serv -start $CTStart -end $CTEnd -ResultSize 99999 | Where-Object {$_.Source -ilike "*STORE*" -and $_.EventID -ilike "*DELIVER*" -and $_.Sender -inotlike "*MicrosoftExchange*"} | Select-Object -Unique InternalMessageId).count Write-Host $CTDayOfWeek $CTToDisplay": "$MailCount } |
MoveMailbox.ps1$UserFile = "users.txt"
$MyData = Import-Csv $UserFile -Delimiter ;
ForEach ($item in $MyData){
$UserIdentity = $($item.UserIdentity)
$TargetDatabase = $($item.TargetDatabase)
$BadTolerance = $($item.BadTolerance)
if ($UserIdentity -match "^*[a-z0-1]@domain.cz$") {
New-MoveRequest -Identity $UserIdentity -TargetDatabase $TargetDatabase -BadItemLimit $BadTolerance
} else {
Write-Host "Bad user login $UserIdentity!" -foregroundcolor "red"
}
}
users.txtUserIdentity;TargetDatabase;BadTolerance
user@domain.cz;exch10_db_1;10
Command to schedule:powershell -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; C:\Scripts\MoveMailbox.ps1"