简体   繁体   中英

Error when using PSSession and Microsoft.Exchange.Management.PowerShell.SnapIn

So trying to run Exchange Management Shell Locally using PSSession, but getting an AD Operation Failure.

Here are my steps

1)open PSmodule as Admin

2)

Enter-PSSession -ComputerName DAG01 -Credential domain\user 

3)

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

4)

Search-Mailbox user -SearchQuery Subject:"anything" -EstimateResultOnly

This is where i get the error. ->

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

Weird thing is that if I RDP with the same credentials into the DAG and run Exchange Management Shell, everything works fine.

You need to pass a pscredential object to the -Credential parameter.

You can use $cred = Get-Credential then -Credential $cred

Get-Credential on technet

This can be used to import a PSSession from your remote exchange server.

$Params = @{
    ConfigurationName = 'Microsoft.Exchange'
    ConnectionUri = "http://youexchangeserver.server.com/PowerShell/"
    Credential = ( Get-Credential )
    Authentication = 'Kerberos'
    Name = 'ExchangeSession'
}
Import-PSSession -Session ( New-PSSession @Params )

However, I am not understanding how yours is working so I would try this:

$Credential = Get-Credential
Enter-PSSession -ComputerName DAG01 -Credential $Credential
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

I will note that if you're running PowerShell as the account that is performing the action, you do not need to even specify credentials.

$creds = Get-Credential

$sess = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://myserver.mydomain.com/PowerShell/ -Authentication Kerberos -Credential $creds

Then do strictly Exchange commands with

Enter-PSSession $sess

Get-Mailbox xyz

Exit

or do some PowerShell + Exchange stuff with

Import-PSSession $sess

Get-Mailbox xyz

.\DoSomthing.PS1

Remove-PSSession $sess

This is from info on https://learn.microsoft.com/en-us/powershell/exchange/exchange-server/connect-to-exchange-servers-using-remote-powershell?view=exchange-ps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM