About: Exchange PowerShell Automation
API Type: Exchange Administration
API Interface: .NET Framework Class Libraries
Business Logic: Managing mailboxes, storage groups, and databases.
Language Support: Any .NET language.
Direct Property Access: N/A
Product Versions: Exchange 2007 and later.
Summary:
Exchange PowerShell was introduced with Exchange 2007 as a replacement of CDOEXM and WMI which were used for Exchange administration. Exchange 2007 did not ship CDOEXM and WMI, which were used by Exchange 2000 and 2003 for administrative tasks. Exchange administrators use these cmdlets manually but they can also be automated by developers using .NET. Automation for Exchange 2007 PowerShell cmdlets required that local PowerShell be used - ie PowerShell 1.0. Exchange 2010 and later require remote PowerShell calls using PowerShell 2.0+.
Exchange PowerShell cmdlets are not meant to work on the content of a mailbox outside of administrative tasks. As an example it cannot be used to read a persons email or calendar content directly. However, the Exchange Managed API (which uses EWS) can be used to access the content of a mailbox and public folders. This can be done by scripting the EWS Managed API or using PowerShell Automation to do both Exchange cmdlet calls and EWS calls. By combining both of these APIs an administrator has some incredible capabilities.
Points of Interest:
Exchange 2007:
- The Exchange Powershell cmdlets are new to Exchange 2007 and automation of these cmdlets replaces CDOEX and WMI.
- The Exchange Admin-Only Role must be installed on the application server in order to use Exchange cmdlets - they cannot be invoked remotely.
- The 64-bit install of Exchange only installs the 64-bit version of Exchange cmdlets - these cmdlets cannot be used from a 32-bit process.
- If an application server has both Exchange 2000/2003 and Exchange 2007 components on it for an application that manages both server versions it must use CDOEXM and PowerShell automation in different processes.
Exchange 2010 and later:
Exchange 2010 and later PowerShell Automation needs to be done with Remote PowerShell 2.0+. Local PowerShell calls are not viable and neither is PowerShell 1.0.
Important:
- Exchange PowerShell automation requires the correct mixture of PowerShell version and call type (Local vs. Remote). Using the incorrect type is not supported. Exchange 2007 PowerShell Automation needs to be done with Local PowerShell 1.0.
- Exchange 2010 and later PowerShell Automation needs to be done with Remote PowerShell 2.0+.
- Exchange PowerShell cmdlets need to run with Exchange Administrative permissions.
- PowerShell itself needs to run with local machine Administrative permissions.
Basic Troubleshooting:
If a remote Exchange PowerShell call fails then be sure to try the following:
1) Always try the same command in the command shell. If it does not work in the command shell then its not going to work with .NET automation.
2) Check to see if a call to non-Exchange cmdlet works. This is important since Exchange cmdlets require Exchange Administrative permissions.
3) Be sure your code is running with the proper permissions and that account used has Exchange Administrative permission.
4) Be sure that the correct version of PowerShell and call type (Local versus Remote) is being used.
Exchange PowerShell - minus automation:
Exchange 2007 PowerShell (PowerShell 1.0):
Windows PowerShell Scripting
https://technet.microsoft.com/en-us/scriptcenter/powershell.aspx
Exchange 2010 and later PowerShell (PowerShell 2.0+):
Using Windows PowerShell
https://technet.microsoft.com/library/dn425048.aspx
Exchange Management Shell
https://msdn.microsoft.com/en-us/library/office/ff326155(v=exchg.150).aspx
Learn How to Use PowerShell to Run Exchange Commands Remotely
https://blogs.technet.com/b/heyscriptingguy/archive/2012/01/23/learn-how-to-use-powershell-to-run-exchange-server-commands-remotely.aspx
Exchange Online:
Exchange Online PowerShell
https://technet.microsoft.com/en-us/library/jj200677(v=exchg.150).aspx
Exchange 2007 PowerShell Automation:
Links on Common PowerShell Automation Questions
HOWTO: csharp - powershell - call get-clusteredmailboxserverstatus with managed code.
https://blogs.msdn.com/b/webdav_101/archive/2007/11/29/howto-csharp-powershell-call-get-clusteredmailboxserverstatus-with-managed-code.aspx
HOWTO: Using PowerShell in ASP.NET (.NET Framework 2.0)
https://blogs.msdn.com/b/akashb/archive/2009/01/30/howto-using-powershell-in-asp-net-net-framework-2-0.aspx
Exchange 2010 and later PowerShell Automation:
With Exchange 2010, use Remote Powershell
https://blogs.msdn.com/b/webdav_101/archive/2009/12/10/with-exchange-2010-use-remote-powershell.aspx
PowerShell Automation from .Net
https://blogs.msdn.com/b/emeamsgdev/archive/2014/03/04/powershell-automation-from-net.aspx
HOW TO: Migrating Exchange 2007 PowerShell Managed code to work with Exchange 2010
https://blogs.msdn.com/b/akashb/archive/2010/03/25/how-to-migrating-exchange-2007-powershell-managed-code-to-work-with-exchange-2010.aspx
More Information:
HOW TO: Configure Exchange 2007 and Exchange 2010 for using Impersonation
https://blogs.msdn.com/b/akashb/archive/2010/03/10/how-to-configure-exchange-2007-and-exchange-2010-for-using-impersonation.aspx
Handling results of calling Powershell - Multivalued and string arrays.
https://blogs.msdn.com/b/webdav_101/archive/2008/02/08/handling-results-of-calling-powershell-multivalued-and-string-arrays.aspx#10274731
Akash blogging on PowerShell autagtion with .NET
https://blogs.msdn.com/b/akashb/archive/tags/powershell/
Using–Filter, Select-Object, ForEach-Object in C# – Exchange PowerShell Automation
https://blogs.msdn.com/b/akashb/archive/2012/08/02/using-filter-select-object-foreach-object-in-c-exchange-powershell-automation.aspx
Call Dispose on client when calling COM+ objects.
https://blogs.msdn.com/b/webdav_101/archive/2008/05/29/call-dispose-on-client-when-calling-com-objects.aspx
Channel 9 - Articles on PowerShell
https://channel9.msdn.com/Search?term=exchange%20powershell#ch9Search
Glen's Exchange Dev Blog
https://gsexdev.blogspot.com/
This is one of my favorite sites for PowerShell scripts.
Glen Scale's Exchagne Column
https://www.outlookexchange.com/articles/glenscales/
Also see:
About: Messaging APIs
https://blogs.msdn.com/b/webdav_101/archive/2015/08/07/about-messaging-apis.aspx