导入远程计算机上的AD模块、Exchange功能命令在本地计算机执行
$RemoteServerDC = "dc01" $RemoteUserName = "xx\ssuser" $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模块,使用http方式 $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