-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove-MailboxSMTPForwardAddress.ps1
More file actions
38 lines (35 loc) · 1.11 KB
/
Remove-MailboxSMTPForwardAddress.ps1
File metadata and controls
38 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function Remove-MailboxSMTPForwardAddress {
<#
.SYNOPSIS
Removing any SMTP Forward from one or multiple mailboxes.
#>
[CmdletBinding(SupportsShouldProcess)]
param (
[Parameter(Mandatory = $true)][String[]]$User
)
begin {
try {
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -ShowBanner:$false
}
catch {
Write-Error $_
}
}
process {
foreach ($mailboxIdentity in $user) {
$userMailbox = Get-Mailbox -Identity $mailboxIdentity
if ($null -eq $userMailbox) {
Write-Error "$mailboxIdentity mailbox doesn't exist"
}
Write-Host "$mailboxIdentity -> " -NoNewline
Write-Host $userMailbox.ForwardingSmtpAddress -ForegroundColor Yellow
Write-Host $userMailbox -ForegroundColor Red
$userMailbox | Set-Mailbox -ForwardingSmtpAddress $Null -WhatIf:$WhatIfPreference
}
}
end {
Write-Verbose "Disconnectiong from ExchangeOnline"
Disconnect-ExchangeOnline -WhatIf:$WhatIfPreference
}
}