使用远程 PowerShell 连接到 Exchange 服务器 https://docs.microsoft.com/zh-CN/powershell/exchange/connect-to-exchange-servers-using-remote-powershell?redirectedfrom=MSDN&view=exchange-ps

#为了使从 Internet 下载的所有 PowerShell 脚本能够由受信任的发布者签名 Set-ExecutionPolicy RemoteSigned

$UserCredential = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<ServerFQDN>/PowerShell/ -Authentication Kerberos -Credential $UserCredential #Basic Import-PSSession $Session -DisableNameChecking

#如果在不断开会话连接的情况下关闭 Windows PowerShell 窗口,您可能会用完可用的所有远程PowerShell 会话,然后您需要等待这些会话过期。 要断开远程 PowerShell 会话,请运行以下命令: Remove-PSSession $Session

在服务器管理器中配置远程管理 https://docs.microsoft.com/zh-cn/windows-server/administration/server-manager/configure-remote-management-in-server-manager

$a= New-PSSession -ComputerName "" -Credential("") invoke-command -session $a -scriptBlock {command xxx} Remove-PSSession $a ------或者需要更多内容: $adminusername="" $adminpassword="" $server ="" $samaccountname="" $UPN="" $pass=convertto-securestring -asplaintext $adminpassword -force $cred= new-object system.management.automation.pscredential -argumentlist $username,$pass invoke-command -computer $server -credential $cred -ArgumentList $samaccountname,$UPN -ScriptBlock { param($samaccountname,$UPN) command xxx }

------或者也可以保持远程会话: Enter-PSSession -ComputerName "" -Credential "" command xxx exit