Exchange Server Share

… Information sharing on Exchange Server …

Exchange 2013 SP1 – Powershell Tips – Part 1

avatar.jpg

I have been collecting all the Tips that are getting displayed when we launch the Exchange Management Shell on an Exchange Server 2013 with Service Pack 1. I have seen quite interesting tips so thought of sharing with all.

There are total #94 tips I have seen so far, I will post them in two different posts, here is the first set of 44 tips (#0 to #43) and I will post remaining 50 tips in next one. I know it has some duplicates but that’s what it’s there.

Exchange 2013 SP1 – Powershell Tips – Part 1 (Current article)

Exchange 2013 SP1 – Powershell Tips – Part 2 (Remaining #50)

image

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #0:

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!

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #1:

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!

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #2:

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!

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #3:

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!

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #4:

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!

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #5:

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

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #6:

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

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #7:

The Exchange Management Shell is a calculator, too! Try it directly at a command prompt:

1.2343+3123 or (23/435)*2

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #8:

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

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #9:

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 -Online

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #10:

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”

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #11:

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.

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #12:

Pushd and Popd work the same way in the Exchange Management Shell as they do in cmd.exe. Type:

Pushd

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #13:

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!

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #14:

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 theServer parameter if the configuration is per server.

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #15:

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}}

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #16:

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}}

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #17:

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”}

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #18:

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}}}

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #19:

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

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #20:

Before you remove an object by using the Remove verb, use the WhatIf parameter to verify the results are what you expect.

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #21:

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”

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #22:

Get all Win32 WMI information, such as Perfmon counters and local computer configurations. For example, type:

Get-WMIObject Win32_PerfRawData_PerfOS_Memory

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #23:

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 -LookupDomain -AnyMatch $True

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #24:

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*” }

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #25:

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

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #26:

Forget a property name? Not a problem because you can use wildcard characters to retrieve all properties that match the part of the name that you specify:

Get-Mailbox | Format-Table Name,*SMTP*

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #27:

Want to work with data contained in a CSV file? Use Import-CSV to assign the data to an object. For example, type:

$MyCSV = Import-CSV TestFile.CSV

You can then manipulate the data easily in the Exchange Management Shell. For example, if there is a column called Mailboxes in the CSV data, you can use the following commands to sort or group the data by the Mailboxes column:

To sort: $MyCSV | Sort Mailboxes
To group: $MyCSV | Group Mailboxes

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #28:

This command spins through all your mailbox servers and reconnects all the uniquely identified but disconnected mailboxes in any one of the mailbox stores:

$Servers = Get-ExchangeServer
$Servers | `
Where { $_.IsMailboxServer -Eq ‘$True’ } `
| ForEach { Get-MailboxStatistics -Server $_.Name `
| Where { $_.DisconnectDate -NotLike ” } `
| ForEach { Connect-Mailbox -Identity `
$_.DisplayName -Database $_.DatabaseName} }

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #29:

Tab completion reduces the number of keystrokes required to complete a cmdlet. Just press the TAB key to complete the cmdlet you’re typing. Tab completion kicks in whenever there is a hyphen (-) in the input. For example:

Get-Send<tab>

should complete to Get-SendConnector. You can even use wildcards, such as:

Get-U*P*<tab>

Pressing the TAB key when you enter this command cycles through all cmdlets that match the expression, such as the Unified Messaging Mailbox policy cmdlets.

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #30:

Tab completion reduces the number of keystrokes required to complete a cmdlet. Just press the TAB key to complete the cmdlet you’re typing. Tab completion kicks in whenever there is a hyphen (-) in the input. For example:

Get-Send<tab>

should complete to Get-SendConnector. You can even use wildcards, such as:

Get-U*P*<tab>

Pressing the TAB key when you enter this command cycles through all cmdlets that match the expression, such as the Unified Messaging Mailbox policy cmdlets.

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #31:

Tab completion reduces the number of keystrokes required to complete a cmdlet. Just press the TAB key to complete the cmdlet you’re typing. Tab completion kicks in whenever there is a hyphen (-) in the input. For example:

Get-Send<tab>

should complete to Get-SendConnector. You can even use wildcards, such as:

Get-U*P*<tab>

Pressing the TAB key when you enter this command cycles through all cmdlets that match the expression, such as the Unified Messaging Mailbox policy cmdlets.

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #32:

Tab completion reduces the number of keystrokes required to complete a cmdlet. Just press the TAB key to complete the cmdlet you’re typing. Tab completion kicks in whenever there is a hyphen (-) in the input. For example:

Get-Send<tab>

should complete to Get-SendConnector. You can even use wildcards, such as:

Get-U*P*<tab>

Pressing the TAB key when you enter this command cycles through all cmdlets that match the expression, such as the Unified Messaging Mailbox policy cmdlets.

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #33:

Want to create a group of test users in your lab? Use this command:

1..100 | ForEach { Net User “User$_” MyPassword=01 /ADD /Domain; Enable-Mailbox “User$_” }

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #34:

Like the Exchange Management Shell Tip of the Day? Try this:

Get-Tip

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #35:

Want to set the properties on all or some Outlook Web Access virtual directories? Pipe the output of Get-OwaVirtualDirectory to the Set-OwaVirtualDirectory cmdlet. For example, the following command sets the Gzip level for all Outlook Web Access virtual directories:

Get-OwaVirtualDirectory | Set-OwaVirtualDirectory -GzipLevel High

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #36:

Want to move your database path to another location? Type:

Move-DatabasePath -EdbFilePath DestFileName

To change the file path setting without moving data, use this command together with the ConfigurationOnly parameter. This command is especially useful for disaster recovery. Caution: Misuse of this cmdlet will cause data loss.

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #37:

Need an easy way to add a new primary SMTP address to a group of mailboxes? The following command creates a new email address policy that assigns the @contoso.com domain to the primary SMTP address of all mailboxes with Contoso in the company field:

New-EmailAddressPolicy -Name Contoso -RecipientFilter {Company -Eq “Contoso”} -EnabledPrimarySMTPAddressTemplate “@contoso.com”

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #38:

Want to retrieve a group of objects that have similar identities? You can use wildcard characters with the Identity parameter to match multiple objects. Type:

Get-Mailbox *John*
Get-ReceiveConnector *toso.com
Get-JournalRule *discovery*

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #39:

Want to configure a group of objects that have similar identities? You can use wildcard characters with the Identity parameter when you use a Get cmdlet and pipe the output to a Set cmdlet. Type:

$Mailboxes = Get-Mailbox *John*
$Mailboxes | Set-Mailbox -ProhibitSendQuota 100MB -UseDatabaseQuotaDefaults $False

This command matches all mailboxes with the name John in the mailbox’s identity and sets the ProhibitSendQuota parameter to 100MB. It also sets the UseDatabaseQuotaDefaults parameter to $False so that the server uses the new quota you specified instead of the database default quota limits.

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #40:

Forgot what the available parameters are on a cmdlet? Just use tab completion! Type:

Set-Mailbox -<tab>

When you type a hyphen (-) and then press the TAB key, you cycle through all the available parameters on the cmdlet. Want to narrow your search? Type part of the parameter’s name and then press the TAB key. Type:

Set-Mailbox -Prohibit<tab>

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #41:

Want to add an alias to multiple distribution groups that have a similar name? Type:

$Groups = Get-DistributionGroup *Exchange*
$Groups | Add-DistributionGroupMember -Member kim

This command adds the alias kim to all distribution groups that contain the word Exchange.

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #42:

Want to record exactly what happens when you’re using the Exchange Management Shell? Use the Start-Transcript cmdlet. Anything that you do after you run this cmdlet will be recorded to a text file that you specify. To stop recording your session, use the Stop-Transcript cmdlet.

Notice that the Start-Transcript cmdlet overwrites the destination text file by default. If you want to append your session to an existing file, use the Append parameter:

Start-Transcript c:\MySession.txt –Append

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Tip of the day #43:

Do you have a user who has network access but maintains an external mail account outside your Exchange organization? With Exchange 2013, you can now create mail-enabled users that are regular Active Directory accounts, but also behave like mail-enabled contacts. By using the Enable-MailUser cmdlet, you can add email contact attributes to any existing Active Directory user who doesn’t already have a mailbox on an Exchange server. Users in your Exchange organization will then be able to send email messages to that user’s external mail account. Type:

Enable-MailUser “Active Directory Alias” -Identity -ExternalEmailAddress “Destination SMTP Address”

-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-

Written by Amit Tank

May 15, 2014 at 9:36 pm

One Response

Subscribe to comments with RSS.

  1. […] Exchange 2013 SP1 – Powershell Tips – Part 1 […]


Comments are closed.

%d bloggers like this: