【发布时间】:2018-02-20 09:08:45
【问题描述】:
我正在编写连接到 Outlook office365(在线交换)的 PowerShell 脚本,如下所示:
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication Basic -AllowRedirection
现在的问题是我想通过具有身份验证的代理服务器进行连接,以下也是
$proxy = New-Object System.Net.WebProxy "http://myproxy:80"
$proxy.Credentials = $cred
[System.Net.WebRequest]::DefaultWebProxy = $proxy
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential
$credential -Authentication Basic -AllowRedirection
但它没有通过我设置的代理连接。所以我做了以下事情:
$proxy = New-Object System.Net.WebProxy "http://myproxy:80"
$proxy.Credentials = $cred
[System.Net.WebRequest]::DefaultWebProxy = $proxy
$sessionOption = New-PSSessionOption -ProxyAccessType IEConfig
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential
$credential -Authentication Basic -AllowRedirection -SessionOption $sessionOption
但仍然没有通过代理。
我也尝试使用netsh winhttp set proxy "myproxy:80",它通过了代理服务器,但它似乎没有身份验证。
有没有办法为 New-PSSession cmdlet 显式设置代理? 注意:我不想在 IE 上设置代理设置,只想为每个会话显式设置代理。
【问题讨论】:
标签: powershell proxy office365 exchange-server