In Exchange Server, we can load Exchange Management Shell module in Windows PowerShell ISE. This way, we can run Exchange cmdlets in PowerShell ISE just like we are used to in Exchange Management Shell. But, is there another way to connect to Exchange Server with PowerShell? This article will teach you how to load Exchange Management Shell snapin in PowerShell ISE.
Table of contents
- Information
- Error when running Exchange cmdlet in PowerShell ISE
- Import Exchange Management Module in PowerShell ISE
- Add Exchange Management snapin Exchange 2010
- Add Exchange Management snapin Exchange 2013/2016/2019
- Without Exchange Management Tools installed
- Connect to Exchange Servers with remote PowerShell
- 1. Enter the credentials
- 2. Provide required connection settings
- 3. Import Exchange cmdlets
- Verify it’s working
- Conclusion
Information
Microsoft PowerShell ISE stands for Integrated Scripting Environment. Why do we like to use Windows PowerShell ISE if it comes to running scripts or cmdlets?
- Works more comfortable with the editor
- Shows you the cmdlets as you type
- Better interface (GUI)
Error when running Exchange cmdlet in PowerShell ISE
If you run an Exchange cmdlet in PowerShell ISE, you will get an error.
PS C:\> Get-MailboxGet-Mailbox : The term 'Get-Mailbox' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.At line:1 char:1+ Get-Mailbox+ ~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-Mailbox:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
You did get this error because you don’t have Exchange Management Module imported in Windows PowerShell ISE.
Import Exchange Management Module in PowerShell ISE
We want to import the Exchange module in PowerShell ISE on the Exchange Server. We also like to do the same on another server with Exchange Management Tools installed.
To load Exchange snapin in PowerShell ISE, you can run the following cmdlets. Run Get-Mailbox cmdlet to verify that it’s working.
Add Exchange Management snapin Exchange 2010
Run PowerShell ISE as administrator. Add the Microsoft Exchange Management snapin.
PS C:\> Add-PSsnapin Microsoft.Exchange.Management.PowerShell.E2010
Add Exchange Management snapin Exchange 2013/2016/2019
PS C:\> Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapInPS C:\> Get-MailboxName Alias ServerName ProhibitSendQuota---- ----- ---------- -----------------Administrator Administrator ex01-2016 UnlimitedAli Tajran Ali.Tajran ex01-2016 UnlimitedAmanda Morgan Amanda.Morgan ex01-2016 Unlimited
We have a management server, and we want to connect to the Exchange Server with PowerShell ISE. If you open it on another server without Exchange Management Tools installed, it will not work.
PS C:\> Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 5.At line:1 char:1+ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (Microsoft.Excha...werShell.SnapIn:String) [Add-PSSnapin], PSArgumentException + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
You get the error because you have to install Exchange Management Tools. After that, run the snapin cmdlet to import Exchange Management Tools.
Connect to Exchange Servers with remote PowerShell
The above Exchange snapin cmdlets will work fine. Is there another way to load the Exchange module in PowerShell? Yes, there is.
In three steps, we can create a remote PowerShell connection to Exchange Server:
- Enter credentials
- Provide required connection settings
- Import Exchange cmdlets
You can connect from Exchange Server itself or another server. For example, a Management Server. The good thing is that you can run this without installing Exchange Management Shell on the remote server. But, some cmdlets will not give you the correct output. For example, the Get-ExchangeCertificate cmdlet will not give you all the properties.
We do recommend to install the Exchange Management Tools on any server to administer Exchange Servers.
Run PowerShell ISE as administrator and run Get-ExecutionPolicy cmdlet to check if it’s correctly set. If it’s not set as RemoteSigned, run the second cmdlet.
PS C:\> Get-ExecutionPolicyPS C:\> Set-ExecutionPolicy RemoteSigned
1. Enter the credentials
PS C:\> $UserCredential = Get-Credential
A prompt will show. Fill in the account UPN with admin privileges.
2. Provide required connection settings
Replace EX01-2016.exoip.local to your Exchange server FQDN. The connectionUri is http and not https.
PS C:\> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://EX01-2016.exoip.local/PowerShell/ -Authentication Kerberos -Credential $UserCredential
3. Import Exchange cmdlets
Import the Exchange cmdlets in the Windows PowerShell session so you can administer Exchange.
PS C:\> Import-PSSession $Session -DisableNameChecking
If you get errors when connecting to the PowerShell virtual directory, read Recreate virtual directories in Exchange Server.
Verify it’s working
Run the Get-Mailbox cmdlet and see the results.
PS C:\> Get-MailboxName Alias ServerName ProhibitSendQuota---- ----- ---------- -----------------Administrator Administrator ex01-2016 UnlimitedAli Tajran Ali.Tajran ex01-2016 UnlimitedAmanda Morgan Amanda.Morgan ex01-2016 Unlimited
If you finished with your work, don’t forget to sign off.
PS C:\> Remove-PSSession $Session
You did connect to Exchange Server from another server or from Exchange server itself. This time with remote PowerShell. Did this load Exchange cmdlets in PowerShell ISE for you?
Keep reading: Install Exchange Online PowerShell module »
Conclusion
In this article, you learned how to load Exchange Management Shell in PowerShell ISE. The next time you connect to the Exchange Server, you can connect with remote PowerShell and not load the Exchange snapin. Both ways will work.
It’s best to Install Exchange Management Tools on any server to administer Exchange Servers. After that, import the Exchange snapin in PowerShell ISE. This way, all the Exchange cmdlets are available.
Did you enjoy this article? You may also like Install Exchange Cumulative Update. Don’t forget to follow us and share this article.