Invoke-Command Exchange

I’m setting up a script to automate our entire termination process and right now I’m stuck with the part where we forward a terminated users emails. Here’s what I got so far:

$ExchangeSession = New-PSSession -ComputerName $ExchangeServer Invoke-Command -Session $ExchangeSession -ScriptBlock {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn} Invoke-Command -Session $ExchangeSession -ScriptBlock {Set-Mailbox $($args[0]) -ForwardingAddress $($args[1])} -ArgumentList $UserName,$ForwardEmailTo 

The error I’m receiving is “Active Directory operation failed on . The supplied credential for ‘Domain Admin’ is invalid.” I’ve tried specifying the credentials with invoke-command and running PoSH as administrator to no avail. The set-mailbox command works properly on the exchange server as well.

Anybody have any ideas that can point me in the right direction for this issue?

submitted by /u/Dilydali
[link] [comments]

Leave a Reply