【发布时间】:2014-10-01 18:25:59
【问题描述】:
我的办公室有一台 Exchange Server 2013。我想找到我使用交换管理 shell 命令找到的有关交换服务器的所有信息。我想查找如下数据。
服务器名称、邮箱数量、邮件联系人数量、信息存储、存储组、最近创建和删除的邮箱、有关通过 Exchange 服务器的所有电子邮件流的信息、有关发件人、收件人的信息以及我从 Exchange 中找到的更多信息服务器。
以编程方式。我想使用 C# 从地理距离以编程方式查找此信息。我的机器上有窗口 7,我想通过它执行此操作。我正在尝试使用带有 C# 的远程电源外壳。 例如,我有一个交换管理 shell 命令,即
Get-mailbox -resultsize unlimited -filter {$_.forwardingaddress -ne $null} | select name, userprincipalname
在使用 Exchange Management Shell 执行上述 cmdlet 后,我得到了一些数据,我想使用 C# 以编程方式获取类似的信息。
我的代码sn-p
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string schemaURI = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";
Uri connectTo = new Uri("https://<serverIP>/powershell/");
string strpassword = "password";
System.Security.SecureString securePassword = new System.Security.SecureString();
foreach (char c in strpassword)
{
securePassword.AppendChar(c);
}
PSCredential credential = new PSCredential("Administrator", securePassword);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(connectTo,schemaURI, credential);
connectionInfo.MaximumConnectionRedirectionCount = 5;
connectionInfo.SkipCACheck = true;
connectionInfo.SkipCNCheck = true;
try
{
Runspace remoteRunspace = RunspaceFactory.CreateRunspace(connectionInfo);
remoteRunspace.Open();
var command = new Command("Get-mailbox");
command.Parameters.Add("resultsize", "unlimited");
command.Parameters.Add("Filter", "{forwardingaddress -ne $null}");
var pipeline = remoteRunspace.CreatePipeline();
pipeline.Commands.Add(command);
var results = pipeline.Invoke();
foreach (PSObject item in results)
{
PSPropertyInfo pinfo = (PSPropertyInfo)item.Properties["Name"];
PSPropertyInfo prop = (PSPropertyInfo)item.Properties["userprincipalname"];
//prop = item.Properties["Name"];
if (pinfo != null)
{
MessageBox.Show(pinfo.Value.ToString());
}
if (prop != null)
{
MessageBox.Show(prop.Value.ToString());
}
}
remoteRunspace.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
行:
remoteRunspace.Open();
产生下面给出的异常:
连接到远程服务器失败并显示以下错误消息:WinRM 客户端无法处理请求。 WinRM 客户端试图 使用协商身份验证机制,但目标计算机 (IP:443) 返回“拒绝访问”错误。更改配置 允许使用协商身份验证机制或指定一个 服务器支持的身份验证机制。使用 Kerberos,将本地计算机名称指定为远程目标。 还要验证客户端计算机和目标计算机是 加入一个域。要使用 Basic,请将本地计算机名称指定为 远程目标,指定基本身份验证并提供用户 名称和密码。报告的可能的身份验证机制 服务器:有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题
如何解决此类异常?
【问题讨论】:
标签: c# powershell exchange-server