1

(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

Tomalak
  • 332,285
  • 67
  • 532
  • 628
new_OOP
  • 11
  • 1

1 Answers1

1

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 }
MikeSh
  • 352
  • 1
  • 5