開発環境と本番環境の両方で、Microsoft.Exchange.Management.PowerShell.RecipientManagement スナップインを使用した Exchange Server の管理ができる状態にしておく必要があります。Exchange Server の管理ツールを使用してハイブリッド環境の受信者を管理する方法を参考に環境を用意してください。
using System; using System.Collections.ObjectModel; using System.Management.Automation.Runspaces; using System.Management.Automation;
namespaceConsoleApp1 { internalclassProgram { staticvoidMain(string[] args) { // Connect Exchange Server using the Microsoft.Exchange.Management.PowerShell.RecipientManagement snap-in in the Exchange Management Tools. // The Exchange Management Tools need to be installed. // Application need to be built as x64 app.
// If you don't know which PowerShell Nuget Packages you should use, read this blog. // https://devblogs.microsoft.com/powershell/depending-on-the-right-powershell-nuget-package-in-your-net-project/ // You need to install Microsoft.PowerShell.5.1.ReferenceAssemblies when you use Windows PowerShell 5.1.
RecipientManagementSnapInPowerShell();
Console.ReadLine(); }
publicstaticvoidWriteStreams(PSDataStreams Streams) { // Write Error, Warning and Information stream