Exchange 2007 Mailbox Setting Configuration Information updation Interval

All Mailbox Settings are stored in Active directory and once you make changes like Storage Quota limits etc it will take 2 hours to reflect for the user. This is because Exchange Cache active directory information every 2 hours. This is known has Mailbox Cache Age Limit. We can change registry settings to reflect the Mailbox settings (Storage) ASAP.  Recommended modification to keep Mailbox Cache Age limit to 1 hour from 2 hours and its also not recommended to limit less then 20 Min

Details description of the registery settings is describited in the below mentioned site

http://technet.microsoft.com/en-us/library/bb684892.aspx

  1. Start the registry editor on your Exchange 2007 Mailbox server
  2. Locate the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSExchangeIS\ParametersSystem key.
  3. Create the “Reread Logon Quotas Interval” value
    1. Right-click ParametersSystem, select New, and then select DWORD value.
    2. Name the new DWORD value “Reread Logon Quotas Interval”.
    3. Right-click Reread Logon Quotas Interval, and then click Modify.
    4. Enter a decimal value of 1200 seconds (20 minutes)
  4. Create the “Mailbox Cache Age Limit” value
    1. Right-click ParametersSystem, select New, and then select DWORD value.
    2. Name the new DWORD value “Mailbox Cache Age Limit”.
    3. Right-click Mailbox Cache Age Limit, and then click Modify.
    4. Enter a decimal value of 20 (20 minutes)
  5. Locate the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MSExchange ADAccess key.
  6. Create the “CacheTTLUser” value
    1. Right-click MSExchange ADAccess, select New, and then select Key.
    2. Name the new key Instance0.
    3. Right-click Instance0, select New, and then select DWORD value.
    4. Name the new DWORD value “CacheTTLUser”.
    5. Right-click CacheTTLUser, and then click Modify.
    6. Enter a decimal value of 300 (5 minutes)
  7. Restart Information Store service to bring the change in Effect Immediately on all the Mailbox store server.

Deleting Disconnected mailboxes from Exchange 2007

By default deleted mailbox retention policy is 30 days and after that deleted mailboxes will be disconnected state for next 30 before its actually gets deleted off the store

Below powershell to get the list of all the users on the specific Exchange server who disconnected mailbox older than 10 days, you can modify the days based on your requirement into the variable $disconnectedUsers

 

$DisconnectedUsers = Get-MailboxStatistics -Server <servername> | where-object { $_.DisconnectDate -ne $null } | ?{$_.DisconnectDate -lt (get-date).AddDays(-10)} | Select DisplayName,Database,MailboxGuid

 

Below command will get the users from variable $DisconnectedUsers one by one in the for loop and delete the same

$DisconnectedUsers | ForEach { Remove-Mailbox -Database $_.Database -StoreMailboxIdentity $_.MailboxGuid -confirm:$false }

Powershell to create Mass Mailboxes in Exchange 2007 from CSV input file

Powershell to create the Mass mailboxes in Exchange 2007 orginisation from CSV input file. Below is the CSV file format which need to have the following header and details in the below mentioned format

Csv Format
Firstname, Lastname,Aliasname,Database,OUPath
Krishna, kumar,krishnakumar,server\storagegroup\store,Users

 

Below is the powershell script to create the mass mailbox by reading the csv file and and create the mailbox. First it take the password as input and reads the csv file and create the mailbox with the information in the csv file

 
$Password=Read-Host “Enter Password” -AsSecureString
Import-CSV C:\CreateNewmailbox.csv |
foreach {
$userprincipalname = $_.Firstname + “.” +  $_.Lastname + “@domain.com”
new-mailbox -name $_.name -alias $_.alias -FirstName $_.Firstname -LastName $_.Lastname -userPrincipalName  $userprincipalname -database $_.Database -OrganizationalUnit  $_.OUpath -Password $Password
}

Powershell to perform Messaging Tracking and Export the Messages details into CSV file

Powershell to perform Messaging Tracking and Export the export the Message details into CSV file

Get-MessageTrackingLog -Sender Krishna.k@domain.com -Start “6/1/09” -End “6/3/09” |select Sender,@{Name=”Recipients”;Expression={$_.recipients}},Recipients,MessageSubject,MessageId,Timestamp| Export-Csv MessagingTracking.csv

Above command can be used to result to the csv file. Multiple option for quering the Messagetrack logs is given below. Modify the query and export the result

Timestamp
ClientIp
ClientHostname
ServerIp
ServerHostname
SourceContext
ConnectorId
Source
EventId
InternalMessageId
MessageId
Recipients
RecipientStatus
TotalBytes
RecipientCount
RelatedRecipientAddress
Reference
MessageSubject
Sender
ReturnPath
MessageInfo

PowerShell to Create New Mailboxes in the smallest database in Exchange 2007 Organization

Loadbalance of the Exchange Database is very important. We need to make sure that  database is not dumped with all the mailbox and once database gets big then move maiboxes to the other database. We can automate this process buy make the script to find the smallest size of the database in the Exchange orginisation and create the mailbox in the same

$MailboxSvr = Get-MailboxServer | select name
$i = 0
foreach($svr in $mailboxsvr)
 {
  $db = Get-MailboxDatabase -Server $svr.Name
  
  foreach($database in $db)
   {
    $Server = $database.Server.Name
    $Db = $database.Identity
    $edbfilepath = $database.EdbFilePath
  
    $path = “`\`\” + $Server + “`\” + $edbfilepath.DriveName.Remove(1) + “$”+ $edbfilepath.PathName.Remove(0,2)
    $Dbsize =  get-item $path |select-object length
    $K = $Server + ” ” + $Db + ” ” + $Dbsize.Length
    if ($i -eq 0 )
     {
     
     $edbsize = $Dbsize.Length
     }
    
    If ($edbsize -gt $Dbsize.Length)
    {
       $edbsize = $Dbsize.Length  
     $sdb = $database.Identity
    } 

    $i = 1
       
   }
    
    
 }
 
Write-output “ENTER THE FOLLOWING DETAILS”
$DName = Read-Host “User Diplay Name  ”
$FName = Read-Host “First Name ”
$LName = Read-Host “Last Name ”
$passwd = Read-Host “Password ” -asSecureString
$PrincipalName = $FName + “.” + $LName + “@domain.com”
$Aliasname = $FName + “.” + $LName
New-Mailbox -Name $DName -Database $sdb -UserPrincipalName $PrincipalName -FirstName $FName -LastName $LName -Alias $Aliasname -Password $passwd -ResetPasswordOnNextLogon $true -SamAccountName $Aliasname

 

You can get the complete copy of the code in the below link file

http://powershell.com/cs/cfs-filesystemfile.ashx/__key/CommunityServer.Components.UserFiles/00.00.00.30.62/NewMailbox_5F00_SmalletDatabase.txt

Executing Exchange Powershell cmdlets and Active directory cmdlets on a single PowerShell

Many times we will have requirement to execute Exchange Comlets and Active Directory(Active Roles) cmdlets on a singlewindow. As we cannot execute exchange cmdlets in  AD shell and vice versa. We have to add snap in to the powershell to execute both cmdlets on a single shell.

1. Need to make sure both Exchange managelent tools and Quest Active role management shell for active directory has been isntalled on the machine
2. Create C:\ExchangeAd.ps1 file with following lines in it

 Add-PSSnapin Quest.ActiveRoles.ADManagement
 Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

3. Open Windows powershell and type C:\exchangead.ps1 to add snapin to the windowspowershell. You can execute both the commands on the single shell
4. Or you can Cretae a bat file which contain follwing line and place into your desktop. For Easy accability

       C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -noexit -command C:\ExchangeAd.ps1

5. You can also execute Quest snapin into Exchange powershell or Exchange snapin into Activeroles shell to execute other commands on the same window.