![](/img/trans.png)
[英]Error when executing PowerShell on target machines using PSSession
[英]Error when using PSSession and Microsoft.Exchange.Management.PowerShell.SnapIn
因此尝试使用 PSSession 在本地运行 Exchange Management Shell,但出现 AD 操作失败。
这是我的步骤
1)以管理员身份打开PSmodule
2)
Enter-PSSession -ComputerName DAG01 -Credential domain\user
3)
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
4)
Search-Mailbox user -SearchQuery Subject:"anything" -EstimateResultOnly
这是我得到错误的地方。 ->
Active Directory operation failed on . The supplied credential for 'domain\user' is invalid.
+ CategoryInfo : NotSpecified: (:) [], ADInvalidCredentialException
+ FullyQualifiedErrorId : [Server=CHGDAG01,RequestId=4f848ef8-264c-4db7-a4e8-2acf2dae560f,TimeStamp=5/13/2016 4:45
:55 PM] [FailureCategory=Cmdlet-ADInvalidCredentialException] 5533B753
奇怪的是,如果我使用相同的凭据通过 RDP 进入 DAG 并运行 Exchange Management Shell,一切正常。
这可用于从远程交换服务器导入 PSSession。
$Params = @{
ConfigurationName = 'Microsoft.Exchange'
ConnectionUri = "http://youexchangeserver.server.com/PowerShell/"
Credential = ( Get-Credential )
Authentication = 'Kerberos'
Name = 'ExchangeSession'
}
Import-PSSession -Session ( New-PSSession @Params )
但是,我不了解您的工作方式,所以我会尝试这样做:
$Credential = Get-Credential
Enter-PSSession -ComputerName DAG01 -Credential $Credential
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
我会注意到,如果您以执行操作的帐户身份运行 PowerShell,则您甚至不需要指定凭据。
$creds = 获取凭据
$sess = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://myserver.mydomain.com/PowerShell/ -Authentication Kerberos -Credential $creds
输入-PSSession $sess
获取邮箱 xyz
出口
导入 PSSession $sess
获取邮箱 xyz
.\DoSomthing.PS1
删除 PSSession $sess
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.