![](/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.