导入远程计算机上的AD模块、Exchange功能命令在本地计算机执行

$RemoteServerDC = "dc01"
$RemoteUserName = "xxssuser"
$RemotePassword = 'password'
$RemotePassword_sec = ConvertTo-SecureString $RemotePassword -AsPlainText –Force
$cred = New-Object System.Management.Automation.PSCredential($RemoteUserName,$RemotePassword_sec)

#导入AD模块
$SessionDC = New-PSSession -Computername $RemoteServerDC -Credential $cred
Import-PSSession $SessionDC -AllowClobber -Module activedirectory

#导入Exchange模块
$SessionMail = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$RemoteServerMail/PowerShell/  -Credential $cred -AllowRedirection 
Import-PSSession $SessionMail -AllowClobber

#在本地计算机上可直接运行AD、Ex命令
Get-Aduser zhangsan
Get-User | Enable-Mailbox -database $db01
原文地址:https://www.cnblogs.com/dreamer-fish/p/14812103.html