The Exchange Management Shell helps us discover the amazing capabilities of PowerShell. One way it does this is by displaying a tip of the day so that we are introduced to concepts and topics that inevitably will come in handy one day!
The other Exchange 2013 tips of the day posts can be found here:
Exchange 2013 Tip Of The Day – 26 To 50
Exchange 2013 Tip Of The Day – 51 To 75
Exchange 2013 Tip of The Day – 76 To 93
Exchange 2010 tips can be found here and the Exchange 2007 Tips are listed on TechNet.
To retrieve the tips listed in this post, this PowerShell code was used to retrieve them:
$Int = 1;While ($Int -le 25){Get-Tip $Int; Write-Host; $Int+=1}
Please refer to the Exchange 2010 tips post for a more verbose version of the PowerShell code.
Just like the Exchange 2010 tips, the first four Exchange 2013 tips are also duplicated, though since they are randomly displayed it goes un-noticed!
Did you know that the Identity parameter is a "positional parameter"? That means you can use:
Get-Mailbox "user" instead of: Get-Mailbox -Identity "user"
It's a neat usability shortcut!
Tired of typing a long command every time that you want to do something? Alias it! Type:
Set-Alias GetMre Get-ManagementRoleEntry
For all the current aliases, type:
Get-Alias
Want to see the members of a dynamic distribution group that has a custom filter? Just use the Get-Recipient cmdlet. Type:
$DDG = Get-DynamicDistributionGroup "Contoso Marketing Managers" Get-Recipient -RecipientPreviewFilter $DDG.RecipientFilter
The Exchange Management Shell is a calculator, too! Try it directly at a command prompt:
1.2343+3123 or (23/435)*2
Command line SOS! Do you need help? Type:
Help <cmdlet-name> or <cmdlet-name> -?
You can choose what information to return when you view Help by using the Detailed, Full, and Examples switches:
Help Get-Mailbox –Detailed
Want to look at Help for a cmdlet but don't want to read through pages and pages of text in the Shell window? Just use the Online switch with the Get-Help cmdlet. The Online switch tells the Shell to open the online version of the cmdlet's Help topic in your default browser. Type:
Get-Help <cmdlet> –Online
The tilde character (~) should be familiar to Unix users. It represents the shortcut to your root directory. To see what it's evaluated to by default, type:
Dir ~
You can use it as a useful shortcut:
Cp SomeFile "~\My Documents"
CTRL+C is the equivalent of the hard-break command in the Exchange Management Shell. If a command is taking too long to run or you want to cancel an operation quickly, press CTRL+C to stop execution.
Pushd and Popd work the same way in the Exchange Management Shell as they do in cmd.exe. Type:
Pushd <location>
XML over everything! The Exchange Management Shell treats XML as a native type, so that you can do interesting things like:
$Sample = [XML](Get-Content SomeXMLFile.xml)
This command assigns $Sample to the actual XML object. To see it, type:
$Sample
To navigate, type:
$Sample.Prop1.Prop2
No need for text parsing when you want to load XML data!
Cmdlets that end in "Config" manage singleton configuration, either one per server or organization. For these tasks, you don't have to specify an identity because there is only one instance of the configuration. You may have to specify the Server parameter if the configuration is per server.
To get a list of all users on an Exchange 2013 server who aren't Unified Messaging-enabled, type:
$Mailboxes = Get-Mailbox $Mailboxes | ForEach { If($_.UmEnabled -Eq $False){$_.Name}}
To get a list of all users on an Exchange 2013 server who are Unified Messaging-enabled, type:
$Mailboxes = Get-Mailbox $Mailboxes = | ForEach { If($_.UmEnabled -Eq $True){$_.Name}}
To display the user's alias formatted in a table together with the user's Exchange 2013 server name and telephone extension, type:
Get-Mailbox | Format-Table ServerName,@{e={$_.SamAccountName};Label="User Alias"},@{Expression="Extensions";Label="Telephone numbers"}
To display the list of UM IP gateway server names disabled for outbound calling and hunt groups associated with a UM IP gateway server, type:
$Gateways = Get-UMIPGateway $Gateways | ForEach {If($_.OutCallsAllowed -Eq $False){ "Gateway Name = " +$_.Name;ForEach ($HuntGroup In $_.Huntgroups ){"Huntgroups " + $Huntgroup}}}
If you want to test all IP Block List providers, you just have to pipe the Get-IpBlockListProvider cmdlet to the Test-IpBlockListProvider cmdlet:
Get-IpBlockListProvider | Test-IpBlockListProvider -IpAddress 192.168.0.1
Before you remove an object by using the Remove verb, use the WhatIf parameter to verify the results are what you expect
Sometimes it's useful to convert the output of a cmdlet to a string to interoperate with native cmdlets. For example, type:
Get-Mailbox | Out-String | Findstr "Administrator"
Get all Win32 WMI information, such as Perfmon counters and local computer configurations. For example, type:
Get-WMIObject Win32_PerfRawData_PerfOS_Memory
Who isn't tired of spam? You can configure real-time block list (RBL) providers with the Exchange Management Shell by running the following two commands:
Set-IPBlockListProvidersConfig -Enabled $True -ExternalMailEnabled $True
and then
Add-IPBlockListProvider -Name <Name of RBL Provider> -LookupDomain <FQDN of RBL Provider> -AnyMatch $True
Access the event log from the Exchange Management Shell. To retrieve the whole event log, type:
Get-EventLog Application | Format-List
To retrieve all Exchange-related events, type:
Get-EventLog Application | Where { $_.Source -Ilike "*Exchange*" }
One benefit of the Exchange Management Shell is that cmdlets can output objects to the console. You can then manipulate this output and organize it in interesting ways. For example, to get a quick view in tabular format, use Format-Table:
Get-Mailbox | Format-Table Name,Database,RulesQuota
Cheers,
Rhoderick
If you would like to have Microsoft Premier Field Engineering (PFE) visit your company and assist with the topic(s) presented in this blog post, then please contact your Microsoft Premier Technical Account Manager (TAM) for more information on scheduling and our varied offerings!
If you are not currently benefiting from Microsoft Premier support and you’d like more information about Premier, please email the appropriate contact below, and tell them you how you got introduced!
US
Canada
For all other areas please use the US contact point.
Thanks
What's the point of repeating Tips 1 - 4? If you want to provide the community with useful information, I would imagine a different tip of the day would be better than the same tip repeated multiple times (even if not on consecutive days).
They are repeated in the underlying XML so that the odds of you seeing them are higher, its an important concept that makes life simpler. They are listed here for completeness, that's all. Just scroll past them please ...... Cheers, Rhoderick