We are on the verge of migrating 20,000 mailboxes from our older Exchange 2003 envivornment over to Exchange 2007. Some of these mailboxes have been around many years on 03, and before. This has created a number of mailboxes that have over time have very mixed up storage limits, usually a decimal place off. For example:
100 mb Warning Limit
10 mb Send/Receive Limit
Because of this, running any Powershell script against our 03 environment, we get tons of warnings. This script is the byproduct of that clean-up.
This script uses both Exchange 2007 powershell commands and Quest ActiveRoles cmdlets (to update the Notes field).
- Find all mailboxes where the order is wrong (like above).
- Modify account notes field of change
- If Notify limit is not set, but Send limit is, set Notify limit to 10% less than Send.
- If Send limit is unlimited, but Notify is set, set Send to Notify + 10mb.
- If Notify limit > Send limit, set Notify to 90% of Send limit
- if Send limit > Send/Receive limit, flip values.
- Set new mailbox values.
$startDate = Get-Date
if ($MisMatchedMbxes -eq $Null) {
$strDate = get-date -uformat "%Y-%m-%d"
$MisMatchedMbxes = Get
-Mailbox
-ResultSize unlimited
| where {$_.UseDatabaseQuotaDefaults
-eq $FALSE -and ($_.prohibitsendquota
-lt $_.issuewarningquota
) -or ($_.prohibitsendquota
-gt $_.prohibitsendreceivequota
)}
$MisMatchedMbxes | select servername
,Displayname
,name
, issuewarningquota
, prohibitsendquota
, prohibitsendreceivequota
| Export-Csv -Path "C:\mbxs_with_bad_quotas"+$strDate+".csv"
}
Start-Transcript "C:\UpdateMailboxQuotas.log"
foreach($Mbx in $MisMatchedMbxes) {
"Working on: " + $Mbx.DisplayName
$SAM = $mbx.SamAccountName
$SAM = $SAM.replace
("@","_at_")
$SAMLngth = $SAM.Length
if ($SamLngth -gt 20){ $SAMLngth = 20}
$SAM = $SAM.Substring
(0,$SAMLngth)
$A = $mbx.issuewarningquota
$B = $mbx.prohibitsendquota
$C = $mbx.prohibitsendreceivequota
$user = Get
-QADUser
-Identity
$mbx.distinguishedname
$IssueWarningChg = $FALSE
$ProhibitSendChg = $FALSE
$ProhibitSRChg = $FALSE
if ($a.IsUnlimited
) {$Astr = "Unlimited"} else {$astr = $a.Value.ToMB
( ).tostring
()}
if ($b.IsUnlimited
) {$Bstr = "Unlimited"} else {$Bstr = $B.Value.ToMB
( ).tostring
()}
if ($c.isunlimited
) {$cstr = "Unlimited"} else {$cstr = $c.Value.ToMB
( ).tostring
()}
if (($a.IsUnlimited
) -and ($b.IsUnlimited
)){
"--------------------------------"
"Checkout: " + $User.DisplayName
"--------------------------------"
} else {
$strNotes = " - Update Quotas from W:"+$astr + ", Send:"+$bstr + ", SndRcv:"+$cstr
if ($User.Notes
-ne $Null) {
if (-not ($User.Notes
-match $strNotes)) {
$Notes = $User.Notes
+ [Environment
]::NewLine
+ (get-date -uformat "%m/%d/%Y") + $strNotes
set
-qaduser
-Identity
$user.DN
-Notes
$notes
}
} else {
$Notes = (get-date -uformat "%m/%d/%Y") + $strNotes
set
-qaduser
-Identity
$user.DN
-Notes
$notes
}
$Notes
if (-not $b.isunlimited
-and $A.IsUnlimited
) {
$a.value
= ($b - ($b.Value.ToBytes
() * .1
))
$IssueWarningChg = $TRUE
}
if (-not $A.IsUnlimited
-and $b.isunlimited
) {
$b.value
= ($a.value.ToBytes
() + 10MB
)
$ProhibitSendChg = $TRUE
}
#if (-not $B.IsUnlimited -and $c.IsUnlimited) {
# $c = ($b + 100MB)
# $ProhibitSRChg = $TRUE
#}
if($A.value
-gt $B.value
) {
# $T = $A
# $A = $B
# $B = $T
$a.value
= ($b - ($b.Value.ToBytes
() * .1
))
$IssueWarningChg = $TRUE
# $ProhibitSendChg = $TRUE
}
if($B.value
-gt $C.value
-and (-not $c.IsUnlimited
) ) {
$T = $B
$B = $C
$C = $T
$ProhibitSendChg = $TRUE
$ProhibitSRChg = $TRUE
}
if ($IssueWarningChg -and $ProhibitSendChg -and $ProhibitSRChg){ Set
-Mailbox
-Identity
$user.DN
-SamAccountName
$SAM -IssueWarningQuota
$A -ProhibitSendQuota
$B -ProhibitSendReceiveQuota
$C }
elseif ($IssueWarningChg -and $ProhibitSendChg -and -not $ProhibitSRChg){ Set
-Mailbox
-Identity
$user.DN
-SamAccountName
$SAM -IssueWarningQuota
$A -ProhibitSendQuota
$B }
elseif (-not $IssueWarningChg -and $ProhibitSendChg -and $ProhibitSRChg){ Set
-Mailbox
-Identity
$user.DN
-SamAccountName
$SAM -ProhibitSendQuota
$B -ProhibitSendReceiveQuota
$C }
elseif ($IssueWarningChg -and -not $ProhibitSendChg -and -not $ProhibitSRChg){ Set
-Mailbox
-Identity
$user.DN
-SamAccountName
$SAM -IssueWarningQuota
$A }
elseif (-not $IssueWarningChg -and $ProhibitSendChg -and -not $ProhibitSRChg){ Set
-Mailbox
-Identity
$user.DN
-SamAccountName
$SAM -ProhibitSendQuota
$B }
elseif (-not $IssueWarningChg -and -not $ProhibitSendChg -and $ProhibitSRChg){ Set
-Mailbox
-Identity
$user.DN
-SamAccountName
$SAM -ProhibitSendReceiveQuota
$C }
else {"------> " + $IssueWarningChg +" "+ $ProhibitSendChg +" "+ $ProhibitSRChg}
}
}
Stop-Transcript
$EndDate = Get-Date
$Results = New-TimeSpan $StartDate $EndDate
"Completed in: "+$Results.minutes
+" minutes"
Comments
Post new comment