Solved

Script needed - Remove all server-side forwarding from mailboxes where the AD account is disabled

Posted on 2016-09-08
7
75 Views
Last Modified: 2016-09-13
Current client NEVER removes old mailboxes. All they do is disable the AD account and set the mailbox to be hidden from the GAL.

However, now they are aware that there are a lot of these that still have active autoforwards set to external addresses. Not good.  So they want these rules gone.
0
Comment
Question by:paulfoel
7 Comments
 
LVL 23

Assisted Solution

by:Brian B
Brian B earned 250 total points
ID: 41790597
Instead of that, why not dump the mailboxes to PST and delete the mailbox? Saves space and you don't have to keep old accounts around.
0
 
LVL 36

Expert Comment

by:Mahesh
ID: 41790606
even if you disable ad account and hide it from GAL, it won't stop receiving new mails on mailbox and since forwarding if removed, it will simply filling space in that mailbox and nobody will see those mails

Better if you delete mailbox as well as suggested above
1
 
LVL 14

Accepted Solution

by:
Todd Nelson earned 250 total points
ID: 41790607
It's a bit more challenging to do for disabled accounts but you stated the accounts are disabled and the mailbox hidden from the address lists.  In that case, lets target those mailboxes that are hidden from the address lists.

For all mailboxes with the HiddenFromAddressListsEnabled parameter set to true, we will disable all forwarding like this...

Get-Mailbox -ResultSize Unlimited | Where { $_.HiddenFromAddressListsEnabled -eq $true } | Set-Mailbox -DeliverToMailboxAndForward $false -ForwardingSmtpAddress $null -ForwardingAddress $null

Open in new window

If you want to do it for a list of users in a CSV file (with DisabledUser as a header), we will do it like this...

Import-CSV "DisabledUsers.csv" | foreach-object { Get-Mailbox -Identity $_.DisabledUser | Set-Mailbox -DeliverToMailboxAndForward $false -ForwardingSmtpAddress $null -ForwardingAddress $null }

Open in new window


Hope this helps.
2
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:paulfoel
ID: 41790808
Thanks all. Yes it would be easier to remove the old accounts of course. BUT its up to my client not me to decide this - I just advise lol.
0
 
LVL 23

Expert Comment

by:Brian B
ID: 41791283
Paul, thanks for getting back to us and accepting the question. Just wanted to ask though why you accepted Mahesh's answer when all he did was agree with me?
0
 

Author Comment

by:paulfoel
ID: 41793829
Brian - my mistake. Your right. I will amend.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question