3

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.

MannyFresh
  • 35
  • 1
  • 3

3 Answers3

2

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

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

Get-Credential on technet

langstrom
  • 1,652
  • 11
  • 14
  • `$User = "Domain01\User01"; $PWord = ConvertTo-SecureString -String "P@sSwOrd" -AsPlainText -Force; $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord` – DustWolf Jan 08 '21 at 15:06
0

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.

Shawn Esterman
  • 2,292
  • 1
  • 10
  • 15
  • That sounds correct but it doesn't work. See: https://learn.microsoft.com/en-us/powershell/exchange/exchange-server/connect-to-exchange-servers-using-remote-powershell?view=exchange-ps – Tim Rivoli Mar 19 '20 at 18:33
  • The first part works but the second part doesn't. It should but doesn't. – Tim Rivoli Mar 19 '20 at 20:15
0

$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

Community
  • 1
  • 1
Tim Rivoli
  • 208
  • 2
  • 5