MannyFresh
MannyFresh

Reputation: 35

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.

Upvotes: 3

Views: 8426

Answers (3)

Tim Rivoli
Tim Rivoli

Reputation: 208

$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

Upvotes: 0

Shawn Esterman
Shawn Esterman

Reputation: 2342

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.

Upvotes: 0

langstrom
langstrom

Reputation: 1702

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

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

Get-Credential on technet

Upvotes: 2

Related Questions