David-Barrett-MS/ExchangePowerShellAutomationSample

A sample application demonstrating how to connect to Exchange Remote PowerShell and run cmdlets programmatically.

★ 8Forks 7C#GitHub ↗Compare

README

Exchange PowerShell Automation Sample

Note: for a more up-to-date sample, see https://github.com/MWC-Developer/PowerShell-Automation-Sample

This sample application shows how to connect to a remote Exchange Powershell session, run cmdlets, and receive data. It also shows how variables can be passed into the PowerShell session from the C# code (currently only PSCredential is supported for the variable type).

The code shows how to connect to the PowerShell session directly (which means that only limited calls can be made, due to the runspace being in RestrictedLanguage mode) or to import the remote session into a local PowerShell session (in which case full scripting should be possible). Note that this only works with Exchange on-premises - Exchange Online cmdlets always run in a local PowerShell session as they are now REST backed.

The code works with Exchange On-premises and Exchange Online (which now requires the EXO v3 PowerShell module).

Contributors

David-Barrett-MSCodeDrop

Issues