-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathForwarding.ps1
More file actions
14 lines (13 loc) · 794 Bytes
/
Forwarding.ps1
File metadata and controls
14 lines (13 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Loop though the object returned by Get-Mailbox with each element represented by $mailbox
foreach ($mailbox in (Get-MailBox -ResultSize Unlimited -OrganizationalUnit "elant.local/SITES [NEW]/Choice"))
{
# Create the forwarding address string
$ForwardingAddress= $mailbox.SamAccountName + “@elantcare.org”
# Check there isn’t a contact, then add one
If (!(Get-MailContact $ForwardingAddress -ErrorAction SilentlyContinue))
{
New-MailContact $mailbox.displayName-ExternalEmailAddress $ForwardingAddress -OrganizationalUnit "elant.local/SITES [NEW]/Choice/Office365Contacts" | Set-MailContact -HiddenFromAddressListsEnabled $true
}
# Set the forwarding address
Set-Mailbox -Identity $mailbox.SamAccountName -ForwardingAddress $ForwardingAddress -DeliverToMailboxAndForward $true
}