Reputation: 11
(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,
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
:
Upvotes: 1
Views: 1322
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
And then either:
a)
Import-PSSession $Session -DisableNameChecking
Get-Mailbox
b)
Invoke-Command -Session $Session -ScriptBlock { Get-Mailbox }
Upvotes: 1