You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows Server 2012 R2执行New-PSSession连接Exchange Online报错“参数不正确”

解决Windows Server 2012 R2上Exchange Online PowerShell远程会话连接失败的问题

我能帮你搞定这个困扰——你在Windows Server 2012 R2(PowerShell 5)上执行New-PSSession连接Exchange Online时遇到的「The parameter is incorrect」报错,大概率是旧系统的兼容性问题导致的,毕竟本地Win7(PowerShell 4)能正常运行,说明脚本逻辑没问题。下面是一步步的排查和修复方案:

1. 先强制启用TLS 1.2再说

Exchange Online现在只支持TLS 1.2及以上版本的连接,而Windows Server 2012 R2默认可能没把TLS 1.2设为优先选项。在你的New-PSSession命令前加这行代码,确保连接用对加密协议:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

2. 升级Windows Management Framework(WMF)到5.1最新版

虽然你用的是PowerShell 5,但Windows Server 2012 R2自带的WMF 5.1可能有旧版本的PSRemoting组件bug,和Exchange Online的远程连接不兼容。去微软官方下载对应的WMF 5.1更新包安装,重启服务器后再试脚本。

3. 重置PowerShell远程配置

有时候服务器的PSRemoting默认设置会阻碍连接,试试重置一下:

# 先禁用再重新启用PSRemoting
Disable-PSRemoting -Force
Enable-PSRemoting -Force
# 把outlook.office365.com加入信任主机列表
Set-Item WSMan:\localhost\Client\TrustedHosts -Value outlook.office365.com -Force
# 重启WinRM服务
Restart-Service WinRM

4. 换用官方的Exchange Online Management模块(更推荐)

传统的New-PSSession方式在旧系统上兼容性确实拉胯,不如直接用微软官方的Exchange Online Management模块,它会自动处理所有连接配置细节,稳定性高很多:

  1. 以管理员身份打开PowerShell ISE,安装模块:
Install-Module -Name ExchangeOnlineManagement -Force -AllowClobber
  1. 把原脚本里的连接代码换成这个:
$ExchangeCredentials = Get-StoredCredential -Target Credentials
Connect-ExchangeOnline -Credential $ExchangeCredentials -ShowBanner:$false

这样就能直接调用Search-UnifiedAuditLog这些命令了,不用再手动导入会话。

5. 计划任务的配置要注意这几点

因为你最终要把脚本设为计划任务,这里还有几个关键配置要检查:

  • 任务必须以管理员身份运行
  • 勾选「不管用户是否登录都要运行」选项
  • 在「操作」里,程序选powershell.exe,参数填-ExecutionPolicy RemoteSigned -File "你的脚本完整路径.ps1"

测试小技巧

每次改完配置,先手动在PowerShell ISE里跑一遍脚本,确认能成功连接Exchange Online后,再去设置计划任务,避免白忙活。


内容的提问来源于stack exchange,提问作者Mark Weir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:28:38