Bulk Disable of Exchange Mailboxes

Hi Readers

I have been given a list of terminated users from previous years to verify that if tey exist in Exchange enviornment & if they exist it needs to be removed.

I have used the condtion that is user account is disabled in AD, hidden from GAL & OU is terminated user OU.

You can use the condition as per the enviornment you are working on.

$data = import-csv $args[0]

foreach ($i in $data)

{

$user = get-mailbox $i.Name

if (($user.HiddenFromAddressListsEnabled -like “True”) -and ($user.UserAccountControl -like “AccountDisabled*”) -and ($user.OrganizationalUnit -like “*Terminated*”))

{

$user1 = $user.SamAccountName

Write-host “$user1 will be disabled”

Disable-mailbox $user1 -Confirm:$false

 

 

 

}

else

{

$user1 = $user.SamAccountName
Write-host “$user1 will not be disabled”

}

}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s