【问题标题】:Error when using PSSession and Microsoft.Exchange.Management.PowerShell.SnapIn使用 PSSession 和 Microsoft.Exchange.Management.PowerShell.SnapIn 时出错
【发布时间】:2016-09-09 23:53:22
【问题描述】:

因此尝试使用 PSSession 在本地运行 Exchange 命令行管理程序,但出现 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 命令行管理程序,一切正常。

【问题讨论】:

    标签: powershell exchange-server exchange-management-shell


    【解决方案1】:

    您需要将pscredential 对象传递给-Credential 参数。

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

    Get-Credential on technet

    【讨论】:

    • $User = "Domain01\User01"; $PWord = ConvertTo-SecureString -String "P@sSwOrd" -AsPlainText -Force; $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
    【解决方案2】:

    这可用于从您的远程交换服务器导入 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 作为执行操作的帐户运行,您甚至不需要指定凭据。

    【讨论】:

    【解决方案3】:

    $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://docs.microsoft.com/en-us/powershell/exchange/exchange-server/connect-to-exchange-servers-using-remote-powershell?view=exchange-ps的信息

    【讨论】:

      猜你喜欢
      • 2017-05-26
      • 2020-04-03
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 2015-11-03
      • 2019-02-21
      • 2015-11-11
      • 2019-11-01
      相关资源
      最近更新 更多