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”
}
}