【发布时间】:2020-02-25 21:28:01
【问题描述】:
我正在用 C# 代码执行 PowerShell 命令。该代码在 O365 中添加了一个电子邮件地址分发列表。 PowerShell 能够将用户添加到分发列表,但它也给出异常。为什么?
using (powershell = PowerShell.Create())
{
command = new PSCommand();
command.AddCommand("Invoke-Command");
string DLGroupName = "UnsubscribersList";
command.AddParameter("ScriptBlock",
System.Management.Automation.ScriptBlock.Create(
"Add-DistributionGroupMember -Identity '" + DLGroupName + "' -Member " + txtEmail.Text + ""));
command.AddParameter("Session", session);
powershell.Commands = command;
powershell.Runspace = runspace;
result = powershell.Invoke();
if (powershell.Streams.Error.Count > 0 || result.Count != 1)
{
throw new Exception("Fail to establish the connection");
}
}
错误:
powershell.Streams.Error 正在抛出
枚举没有结果
result.Count 为 0
【问题讨论】:
标签: c# powershell office365