$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