How to Run the Exchange Management Shell EMS in PowerShell

Home > Blogs > Exchange Server > How to Run the Exchange Management Shell EMS in PowerShell

How to Run the Exchange Management Shell EMS in PowerShell

Like This Blog 1 Mike Pfeiffer
Added by April 30, 2013

How to Run the Exchange Management Shell EMS in PowerShell
Instructor: Mike Pfeiffer

Let’s take a look at a couple of ways that you can use the Exchange Management Shell in a scripting environment. We’ll go beyond just working interactively in the Shell and actually composing real world robust scripts.

We’ll use a scripting editor and make sure that we can get the Exchange environment loaded as well. Then we’ll also look at some common scenarios like some basic report generation and scheduling some scripts so they’ll run automatically for you in the background.

When you install an Exchange Server, you get the Exchange tools installed along with it which gives you the Exchange Management Shell (EMS). But what a lot of us do when we’re managing Exchange Server is actually install those tools locally on our desktops. So for example, this Windows 7 machine, you can see that I’ve got the Exchange Management Console.

Exchange Management Shell in PowerShell

Hopefully, this is familiar to you. But I can also go into All Programs under Exchange 2010. You can see that I have the Exchange Management Shell shortcut.

Exchange Management Shell (EMS) in PowerShell from Start Menu

So this is basically just a customized version of your typical powershell.exe.

What will happen here is in my environment when I fire up this instance of Exchange Management Shell, we’re actually going to go out in an Active Directory and trying to locate an Exchange Server in the current Active Directory site that I’m sitting in. Sometimes, this first run will take a little bit of time.

You can see that it hung there, but what it’s doing right now is it’s connecting to exchange.uss.local, so that’s a server that’s remote to where I’m sitting.

Once that comes up, I can do things like run “get mailbox,” that will show me all the mailboxes that are out there. What’s happening is that command is really executing on the Exchange Server, on exchange.uss.local.

Get Mailbox in Exchange Management Shell

Now if we look at the typical PowerShell, blue PowerShell console, that you’re probably used to that’s located under Accessories > Windows PowerShell.

PowerShell Console Exchange Management Shell (EMS)

This is just powershell.exe, and when you run this you don’t actually get the Exchange tools even though you might have them installed locally. So here, if I try to run get mailbox, I’m going to get an error there because we haven’t really told this instance of PowerShell that we want the Exchange tools loaded.

PowerShell Console Get Mailbox Exchange Management Shell (EMS)

When you run this shortcut, let’s take a look at that, we’ll go into Programs and go into the Properties of the Exchange Management Shell.

Properties Exchange Management Shell (EMS) in PowerShell

You can see that we’re really calling as the target for this shortcut, we’re calling PowerShell.exe.

If you look further down the Target, we’re actually importing this PS1 script that gets installed with the tools.

Properties PS1 Script Exchange Management Shell (EMS) in PowerShell

So this script has bunch of variables and shell specific functions and things like that one of those being “connect Exchange Server.”

So we’re basically firing up the powershell.exe and then running some additional commands to kind of customize this view. Change the icon. Make the background black instead of blue.

And it actually gets the Exchange Commands loaded and connected to a server automatically in your environment. Now, one of the nice things about Exchange is that we have the ability to do remote connections.

We’re actually doing that right now with this. You can see up here, we’re actually connected to this Exchange Server remotely even though the tools are installed. But you don’t actually have to have the tools installed. We could actually use the typical blue shell from any machine that has PowerShell version two installed and get connected to the Exchange Server.

So if you wanted to manually set this up, maybe you have an XP machine that’s 32‑bit, the Exchange Tools are 64‑bit, so you can’t install those there. You can still use PowerShell v2 to connect. Let me show you how you do that.

First of all, you want to create a session variable. You use the new PSSession cmdlet to do that.

PowerShell Remoting Session variable in Exchange Management Shell

The configuration name is going to be –ConfigurationName microsoft.exchange

PowerShell Remoting configurationname in Exchange Management Shell

In this case, you need to manually specify the server you want to connect to. In my environment, that’s http://exchange.uss.local/powershell

PowerShell Remoting specify server in Exchange Management Shell

I’m actually already logged into Windows with a user that has permissions to run the Exchange Commands.

So you can see there that I’ve created that variable and didn’t get any errors back.

So now I should be able to import that variable. Import-PSSession $s

Import Variable Exchange Management Shell in PowerShell

That will go out and pull those commands from the Exchange Server.

Now that that’s loaded, I can go ahead and run get mailbox, and this time that should run without any errors.

So that’s basically two ways that you can run this Shell, either when the tools are installed using the Exchange Management Shell shortcut or using the blue shell whether the tools are installed or not.

More online training videos from Interface Technical Training.

For Instructor-Led live classes, see our complete Course Schedule. Many courses are available online with RemoteLive™.

Videos You May Like

Agile Methodology in Project Management

0 114 0

In this video, you will gain an understanding of Agile and Scrum Master Certification terminologies and concepts to help you make better decisions in your Project Management capabilities. Whether you’re a developer looking to obtain an Agile or Scrum Master Certification, or you’re a Project Manager/Product Owner who is attempting to get your product or … Continue reading Agile Methodology in Project Management

Creating Users and Managing Passwords in Microsoft Office 365

0 495 3

In this Office 365 training video, instructor Spike Xavier demonstrates how to create users and manage passwords in Office 365.

Detailed Forensic Investigation of Malware Infections – April 21, 2015

4 478 3

In this IT Security training video, Security expert Mike Danseglio (CISSP / CEH) will perform several malware investigations including rootkits, botnets, viruses, and browser toolbars.

Write a Comment

See what people are saying...

  1. Avatar Gary

    If you want to run EMC 2016 in Windows 2012 use:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command “. ‘C:\Program Files\Microsoft\Exchange Server\V15\bin\Exchange.ps1’

Share your thoughts...

Please fill out the comment form below to post a reply.