0

我正在用 C# 编写一个 .Net 组件,它需要为 Exchange Online 打开远程 Powershell 连接以执行 cmdlet。但是,在本地计算机和 Internet 之间有一个 Web 代理服务器。我没有在 IE 中提供代理服务器设置。在打开远程运行空间时,我需要以某种方式提供 Web 代理服务器的 IP 地址和端口号。

我正在使用以下代码:

PSCredential credential = new PSCredential(userEmail, securePassword);

connectionInfo = new WSManConnectionInfo(new Uri("https://ps.outlook.com/powershell"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);

connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
connectionInfo.MaximumConnectionRedirectionCount = 2;               

runspace = RunspaceFactory.CreateRunspace(connectionInfo);
runspace.Open();

powershell.Runspace = runspace;

//Create the command and add a parameter
powershell.AddCommand("Get-MailboxFolderStatistics");
powershell.AddParameter("identity", sMailbox);
...
...
...
pipeline = remoteRunspace.CreatePipeline()
foreach (Command command in cmdlet.GetCommands())
{
   pipeline.Commands.Add(command);
}
commandResults = pipeline.Invoke();

我应该在 Runspace 对象的 RunspaceconnectionInfo 的 ProxyAccessType、ProxyCredentials、ProxyAuthentication 属性中提供什么。

有没有办法通过提供 Web 代理服务器设置来打开远程运行空间,而无需在 IE 中进行代理设置。我想通过我的应用程序中的用户界面将代理服务器 ip 和端口传递给我的 api

请建议。

谢谢,加根

4

2 回答 2

0

例如,如果您想配置代理以与提琴手一起使用,您可以这样做:

PSSessionOption sessionOptions = new PSSessionOption();
sessionOptions.ProxyAccessType = ProxyAccessType.IEConfig;
sessionOptions.ProxyAuthentication = AuthenticationMechanism.Negotiate;
wsManConnectionInfoInstance.SetSessionOptions(sessionOptions);
于 2015-01-20T08:10:34.040 回答
0

可以使用 New-WSManSessionOption 配置代理设置

http://technet.microsoft.com/en-us/library/hh849874.aspx

于 2013-11-11T10:29:59.093 回答