Well, without seeing the Invoke-Command you’re trying to use, it’s a little difficult to tell. That error message is telling you that the credential you supplied is not valid. Since I can’t tell what credential you provided… hard to say.
Assuming that you have an account in the same domain as the Exchange servers, and that the account has permission to use Remoting on the Exchange servers, and that you specify that account when running Invoke-Command, then it should run fine. But there are a zillion configuration things on the Exchange side that could restrict it from working, and without sitting in front of the computers, it’s a little tough to diagnose.
Ultimately, you probably do want to have the command running on each server, and run Get-Mailbox with its -Server parameter to restrict each server to only searching its own mailboxes.
But I’d maybe start with a simple Enter-PSSession command to one of the servers. Get that working first, and then move on to your actual command.
I will try with Enter-PSSession and work slowly forward. But here is my setup:
All workstation and servers are in same AD domain. I start ISE with admin cred and don’t supply them in PSSession command.
This runs in my profile scipt:
$ex=New-PSSession -ConfigurationName microsoft.exchange -ConnectionUri http://ex05.domain.no/powershell
import-pssession $ex
And with Exchangecmdlets via Implicit Remting i try to run:
$servers=Get-TransportService | select -ExpandProperty name
foreach ($server in $servers) { Invoke-Command -ComputerName $server -FilePath .\Remove-mail.ps1 }