Category Archives: Powershell

Mailboxes not logged into within the last 30 Days

Below is a powershell command that will return all mailboxes not logged into within the last 30 days:

Get-MailboxStatistics -Database “Server\Database” | where {$_.LastLogonTime -lt (Get-Date).AddDays(-30)} | ft DisplayName, LastLogonTime, LastLoggedonUserAccount, Servername


Retrieving Disconnected Mailboxes from an Exchange Server

The command below will retrieve disconnected / deleted mailboxes from a given Exchange server using Powershell.

Get-MailboxStatistics -Server <server> | where { $_.DisconnectDate -ne $null } | Select Displayname, DisconnectDate, TotalItemSize -Autosize

Below is a Powershell command to retrieve disconnected mailboxes for the last 7 days:

Get-MailboxStatistics -Server corp2k7mail | Where-Object {$_.DiscconnectDate -gt (Get-Date).AddDays(-7)} |ft Displayname, ServerName, DatabaseName, TotalItemSize –Autosize

To reconnected a disconnected mailbox to a user object still in AD type:

Connect-Mailbox -Database <Mailbox_Database> -Identity <Deleted_Mailbox>


Exchange DB and Mailbox Total Count

I was recently ask to provide the total number of Exchange mailboxes.  Simple question, but I notice one of my co-workers working on a powershell cmd to retire the data.  Below is the powershell cmd that would retire that data:

 (Get-Mailbox).count

Or, just open the Exchange Management console click the Mailbox icon located under the Recipient Configuration.  Then look at the total number of objects located at the top right corner.

But, what about the total number of Exchange databases:
(Get-Mailbox -ResultSize:Unlimited | Group-Object -Property:Database).count

The powershell cmd below returns all of the databases names:
(Get-Mailbox -ResultSize:Unlimited | Group-Object -Property:Database | Select-Object -Property:Name)

The powershell cmd below returns total mailbox count per database and the database name:
(Get-Mailbox -ResultSize:Unlimited | Group-Object -Property:Database | Select-Object -Property:Count,Name)


Sending a copy of NDR’s to the Postmaster Mailbox

Troubleshooting Non-Delivery Reports (NDR) is a normal administrative task of anyone who supports emails.  The information provided on an NDR will help resolve the issue.  Getting the NDR’s would require the recipient to send a copy of the email to the administrator.  Which is also considered to be retroactive because you’re not proactively solving the issue(s).

Or, you can configure a mailbox to automatically receive a copy of those NDR’s.  This method allows the administrator to troubleshoot and proactively resolve issues before receiving any tickets.

  1. To make sure the company has not already setup a postmaster account open powershell and type:
    • Get-TransportServer

      The ExternalPostmasterAddress has not been configured because it’s empty.
  2. To assign a mailbox type the following command:
    • Set-TransportServer -ExternalPostmasterAddress postmaster@domain.com
      Excute the command below to make the change on all the Hub Transport
    • Get-TransportServer | Set-TransportServer -ExternalPostmasterAddress postmaster@domain.com:
  3. Now you must associate an internal mailbox to receive the NDR’s.
    • Set-OrganizationConfig -MicrosoftExchangeRecipientReplyRecipient postmaster@domain.com

Make sure to create a postmaster mailbox for the email delivery.  This is done the same way a users mailbox is created.

References: http://technet.microsoft.com/en-us/library/bb400930(EXCHG.80).aspx


Duplicating Exchange Receive Connectors on a 2nd Hub Transport

You may want to duplicate the receive connectors for your Hub Transport (HT) servers if your company has more than one HT.  This would eliminates a single point of failure with your HT’s receive connectors.  The company I work for only allows approved internal IP’s to send email to Exchange for relays.  An example of this is a server sending out reports to Exchange for recipient delivery.  As a result, any emails received from a non-approve servers will fail.  The approved list of IP’s can add up to the hundreds, depending on your organization size.  We currently have 150+ approved IP’s for internal email relay. 

The purpose of the script listed below is to duplicate a receive connector on a second HT with minimum effort on the Exchange Administrator.

To retrieve the existing Receive connectors in your Exchange organization please enter:

Get-ReceiveConnector

Now, here’s the script to copy an existing receive connector:

$ReceiveCTR = Get-ReceiveConnector “<HT-Srv-Name>\<ReceiveConnectorName>”
$ReceiveCTR.RemoteIPRanges
New-ReceiveConnector -Name ‘Name-of-the-ReceiveConnector’ -Usage ‘Internal’ -Server ‘2nd-HT-Srv-Name’ -RemoteIPRanges $ReceiveConnector.RemoteIPRanges

Here’s an example of the process:

Get-ReceiveConnector

We will be duplicating the receive connector “Test” located on corpmailxxx on corpmailxxx1. 

$ReceiveCTR = Get-ReceiveConnector “CORPMAILXXX\Test”
$ReceiveCTR.RemoteIPRanges

New-ReceiveConnector -Name ‘Test’ -Usage ‘Internal’ -Server ‘CORPMAILXXX1’ -RemoteIPRanges $ReceiveCTR.RemoteIPRanges

Lets confirm that the receive connector has been duplicated by entering the powershell CMD:

Get-ReceiveConnector

References:

http://technet.microsoft.com/en-us/library/bb690954.aspx#Shell


DistributionGroup Change from “Mail Non-Universal” to “Mail-Enabled Universal” Group

Microsoft will no longer allow the creation of mail enable non-universal groups.  This is true starting with Exchange 2007.  Why the change?  That’s because MailEnableNonUniversalGroup will not replicated to the entire AD forest.  As a result, some emails were never received to all the intended members of a distribution group.  This only occurred in an Active Directory forest with several child domains.  As a result, the only mail enable groups allowed will be Universal.  Universal groups are replicated to all global catalogs servers in the forest.  You will notice MailEnableNonUniversalGroup in Exchange 2007 or newer if you performed an upgrade from Exchange 2003 organization.  Microsoft strongly recommends upgrading all these groups to MailEnableUniversalGroup.  Here’s the EMS CMD:

To retrieve the MailEnableNonUniversalGroup names:

Get-DistributionGroup | Where{$_.RecipientType -eq “MailEnableNonUniversalGroup”}

Here’s how to change one group type:

Set-Group “<Group Name>” -Universal

Here’s how to change all the MailEnableNonUniversalGroup at once:

Get-DistributionGroup | Where{$_.RecipientType -eq “MailEnableNonUniversalGroup”} |Set-Group -Universal


Configuring ResourceCustom for A Resource Mailbox

Resource mailboxes are great option in Exchange.  But what good are they if you have to walk over to a room to see what resources are available (LCD, Video Conference, projector, etc.).  Great exercise, but no as productive as it should be.  Below is the PowerShell CMD’s that will add the resource(s):

First step is to add all the available resources you have in your company.  Here’s the PowerShell CMD to accomplish it:

Set-ResourceConfig -ResourcePropertySchema(“Room/<ResourceName>”, “Room/<ResourceName2>”)

Example: Set-ResourceConfig -ResourcePropertySchema(“Room/42in LCD”, “Room/60in LCD”, “Room/Video Conference”)

Second step is to add the resource type to a Room resource mailbox:

Set-Mailbox “<mailbox name>” -ResourceCustom (“42inLCD”) -ResourceCapacity 10

The -ResourceCapacity can be left out.  Done….



Mailbox Move Request – Exchange 2010

Exchange 2010 has a new and very welcome feature that allows an Exchange admin the ability to move a mailbox from one database to another with minimum downtime.  Employees using Outlook 2007 and newer will receive an alert to restart Outlook “after” the move is compete.  In pervious version of Exchange the employee would have lost connection “until” the move was complete.  However, Outlook Web App may experience an outage due to AD replication.  (Error below)

Heres the command:

New-MoveRequest  <employees-email-address> -Confirm:$False

If you notice the command above does not list the destination database.  That’s because Exchange 2010 will automatically load balance the database for you.  Nice Right !?!  Well, I guess not in all cases.  As a result, you can specify the database if you need too by adding the -TargetDatabase option.  Example below:

New-MoveRequest  <employees-email-address> -TargetDatabase -Confirm:$False

Once the move has completed you must clear the request log.  The employee’s icon in the EMC will have a green arrow until the request has been removed.  This is true even if the move has completed.  The employee won’t be able to access their mailbox using OWA until the request has been cleared.  Image below:

Yes, Oprah Winfrey and Barack Obama work for my factitious company.  The command listed below will return information about move request with a status of complete:

Get-MoveRequest | Where {$_.status -eq “Complete”}

or

Get-MoveRequest | Get-MoveRequestStatistics

Below is the command to clear the move request.  Remember, you must clear the move request in order to allow OWA access:

Get-MoveRequest | Remove-MoveRequest -Confirm:$False

After refreshing your console you will notice that the green arrow has disappeared.  Image below:


Creating a New User & Assigning a Mailbox using EMS

To create a new account in active directory and a new Exchange mailbox please use the PowerShell command below:

New-Mailbox -Name ‘John Doe’ -Alias ‘John.Doe’ -OrganizationalUnit
‘yourdomain.com\Users’ -UserPrincipalName ‘John.Doe@yourdomain.com’ -SamAccountName ‘John.Doe -FirstName ‘John’ -Initials ” -LastName ‘Doe’ -ResetPasswordOnNextLogon $True -Database ‘MBX-001’ -Archive

Note: Automatic Distribution of Mailboxes will be used if -Database is removed from tis command.


Disabling Automatic Distribution of Mailboxes

 

Exchange 2010 has a new feature that automatically load balances mailboxes across the databases.  This is a well needed and greatly appreciated new feature.  However, there are situations where you don’t want the database to be a part of the load balancing.  An example of this is a journaling database or if you’re going to place a database in maintenance mode.  Here’s the EMS command:

Set-MailboxDatabase –Identity ‘MBX-001’ -IsExcludedFromProvisioning $True

Or

Set-MailboxDatabase –Identity ‘MBX-001’ -IsSuspendedFromProvisioning $True

What’s the difference between “IsExcludedFromProvisioning” & “IsSuspendedFromProvisioning”? Good Question! “IsSuspendedFromProvisioning” is to temporary disable the database from Automatic distribution of mailboxes.  This is good if you’re planning maintenance on the database.

IsExcludedFromProvisioning” is to permanently disable automatic
distribution of mailboxes.  An example of this is when you’re planning on using the database for mailbox journaling.

Note: To place the database back into the load balance just change the $True to $False.