簡體   English   中英

使用 PSSession 和 Microsoft.Exchange.Management.PowerShell.SnapIn 時出錯

[英]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,一切正常。

您需要將pscredential對象傳遞給-Credential參數。

您可以使用$cred = Get-Credential然后-Credential $cred

在 technet 上獲取憑證

這可用於從遠程交換服務器導入 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

出口

或者做一些 PowerShell + Exchange 的東西

導入 PSSession $sess

獲取郵箱 xyz

.\DoSomthing.PS1

刪除 PSSession $sess

這是來自https://learn.microsoft.com/en-us/powershell/exchange/exchange-server/connect-to-exchange-servers-using-remote-powershell?view=exchange-ps上的信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM