new_OOP
new_OOP

Reputation: 11

ADInvalidCredentialException with PowerShell remote management for Exchange 2010

(My English is bad) Hi Techies,

I am trying to get Mailbox statistics using Remote PowerShell with cmd executed as an Administrator.

powershell -command "$session=New-PSSession -ComputerName 'EX2' -Credential $cred; invoke-command -Session $session -ScriptBlock { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; dir env:}"

this command is ok,

command output

but I change the command to Get-MailboxDatabase

powershell -command "$session=New-PSSession -ComputerName 'EX2' -Credential $cred; invoke-command -Session $session -ScriptBlock { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; Get-MailboxDatabase -Status}"

I get an ADInvalidCredentialException:

error output

Upvotes: 1

Views: 1322

Answers (1)

MikeSh
MikeSh

Reputation: 432

You have to connect to Exchange Server as follows:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<ServerFQDN>/PowerShell/ -Authentication Kerberos -Credential $UserCredential

see Microsoft Docs article

And then either:

a)

Import-PSSession $Session -DisableNameChecking
Get-Mailbox

b)

Invoke-Command -Session $Session -ScriptBlock { Get-Mailbox }

Upvotes: 1

Related Questions