Join Mike Pfeiffer for an in-depth discussion in this video Run the Exchange Management Shell, part of PowerShell 2.0 for Exchange Server.
- [Voiceover] When you install an Exchange server you get the Exchange tools installed along with that. That gives you the console. That gives you the Exchange Management Shell. But what a lot of us do when we're managing Exchange is actually install those tool locally on our desktops. So, for example, this Windows 7 machine I'm on you can see that I've got the Exchange Management console. Hopefully this is familiar to you. But I can also go in to all programs under Exchange 2010, and you can see that I have the Exchange Management Shell shortcut. So this is basically just a customized version of your typical PowerShell.exe.
So let me go ahead and run this, and what will happen here is in my environment, when I fire up this instance of the Exchange Management Shell, we're actually going to go out in active directory and try to locate an Exchange server in the current active directory site that I'm sitting in. And sometimes this first run will take a little bit of time. You can see that I kind of 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. But once that comes up I can do things like, run Get-Mailbox, that will show me all the mailboxes that are out there.
And what's happening, is that command is really executing on the Exchange server, on Exchange.uss.local. Now if we look at the typical blue PowerShell console that you're probably used to, and that's located under "Accessories," Windows PowerShell, 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 tried 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.
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. You can see that we're really calling, as the target for this shortcut, we're calling PowerShell.exe. And if you look further down the road, we're actually importing this PS one script that gets installed with the tools. So this script has a bunch of variables and Shell-specific functions and things like that. One of those being ConnectExchangeServer. So we're basically firing up PowerShell.exe, and then running some additional commands to kind of customize this view.
Change the icon. Make background black instead of blue. And actually get the exchange commands loaded and connected to a server automatically in your environment. Now one of the things that's nice about Exchange is that we have the ability to do remote connections. And 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 can actually use the typical blue shell for 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 version two to connect, and let me show you how you do that. First of all, you want to create a session variable. And use the "New-PSSession" command to do that. The configuration name is going to be Microsoft.exchange. And in this case you would have to manually specify the server you want to connect to. My environment, that's exchange.uss.local/powershell.
And that's actually good enough. I'm actually already logged in to Windows with a user that has permissions to run the Exchange commands. 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. And 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 the 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.