Using PowerShell Command to get data from Exchange

This will show how to use powershell command to get information from exchange server.

1. PowerShell

PowerShell is an object-oriented programming language and interactive command line shell for Microsoft Windows.

PowerShell was designed to automate system tasks, such as batch processing, and create systems management tools for commonly implemented processes. The PowerShell language is similar to Perl. PowerShell includes more than 130 standard command line tools for functions that formerly required users to create scripts in VB, VBScript or C#.

PowerShell offers a variety of ways to automate tasks, including:

  • Cmdlets, which are very small .NET classes that appear as system commands.
    Scripts, which are combinations of cmdlets and associated logic.
  • Executables, which are standalone tools.
  • Instantiation of standard .NET classes.

PowerShell integrates with the .NET environment and can also be embedded within other applications. Over a hundred cmdlets are included that can be used separately or combined with others to automate more complex tasks. Users can also create and share cmdlets.

PowerShell is available as a free download for Windows XP, Windows Server 2003 and Windows Vista. Support for PowerShell is built into Windows Server 2008 and Windows 7, where it is included as an optionally installed feature.

Ref:http://searchwindowsserver.techtarget.com/definition/PowerShell

2. Exchange Management Shell

Using powershell by open Exchange Management Shell

Start > All Programs > Microsoft Exchange Server 2010 > Excahnge Management Shell

Right click > Run as Administrator

Click "Yes"


Powershell command prompt

3. Example Command

_
Get-MailBoxStatistics: MailboxSize
Get-MailboxStatistics -Server MXS1 | where {$_.ObjectClass –eq “Mailbox”} | Sort-Object TotalItemSize –Descending | ft DisplayName, TotalItemSize, ItemCount > C:\mailboxsize.txt


Get-MailboxStatistics from -Server MXS1 where Mailbox Sort-Object TotalItemSize -Descending ft DisplayName, TotalItemSize, ItemCount(ft=Format table)

Convert result to localtion C:\mailboxsize.txt

Result

Get-MailBoxStatistics: LastAccess
Get-MailboxStatistics -Server MXS1 | Sort-object itemcount -Descending

Get-MailboxDatabase: DatabaseSize
Get-MailboxDatabase -Status | select ServerName,Name,DatabaseSize

Get-Mailbox: ForwardingAddress
Get-mailbox | select PrimarySMTP,ForwardingAddress | where {$_.ForwardingAddress -ne $Null}

Get-Mailbox: WhenCreate
Get-mailbox | ft dispalyname, alias, whencreated, userprincipalname, organizationalunit