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

2 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

A Simple Introduction to Cisco CML2

0 3896 0

Mark Jacob, Cisco Instructor, presents an introduction to Cisco Modeling Labs 2.0 or CML2.0, an upgrade to Cisco’s VIRL Personal Edition. Mark demonstrates Terminal Emulator access to console, as well as console access from within the CML2.0 product. Hello, I’m Mark Jacob, a Cisco Instructor and Network Instructor at Interface Technical Training. I’ve been using … Continue reading A Simple Introduction to Cisco CML2

Creating Dynamic DNS in Network Environments

0 642 1

This content is from our CompTIA Network + Video Certification Training Course. Start training today! In this video, CompTIA Network + instructor Rick Trader teaches how to create Dynamic DNS zones in Network Environments. Video Transcription: Now that we’ve installed DNS, we’ve created our DNS zones, the next step is now, how do we produce those … Continue reading Creating Dynamic DNS in Network Environments

Cable Testers and How to Use them in Network Environments

0 727 1

This content is from our CompTIA Network + Video Certification Training Course. Start training today! In this video, CompTIA Network + instructor Rick Trader demonstrates how to use cable testers in network environments. Let’s look at some tools that we can use to test our different cables in our environment. Cable Testers Properly Wired Connectivity … Continue reading Cable Testers and How to Use them in Network Environments

Write a Comment

See what people are saying...

    Share your thoughts...

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