Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- If ($ForwardEmailTo -ne $NULL) {
- $ExchangeServer = 'ServerName'
- $Block = {
- Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
- Set-Mailbox $args[0] -forwardingaddress $args[1]
- }
- Write-Warning "Forwarding $UserName emails to $ForwardEmailTo"
- Invoke-Command -Session (New-PSSession -ComputerName $ExchangeServer -Authentication Kerberos) -ScriptBlock $Block -ArgumentList $UserName,$ForwardEmailTo
- Get-PSSession | Remove-PSSession
- Write-Verbose "Emails sent to $UserName are now being forwarded to the following user:"
- }
- Else {
- Write-Warning "Emails for $UserName are not being forwarded. Check who these need to be forwarded to and set this in the Exchange Console."
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement