Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

BulkUserTermination

$
0
0

##This will write the database informationin the Notes field and then remove the mailbox from the account.

Write-Host "When creating your CSV file, be sure to use only the ALIAS, SAMACCOUNTNAME, or FULL DISPLAYNAME"

Start-Sleep 5

add-pssnapin quest.activeroles.admanagement

$FileLocation = read-host -prompt "Full CSV Import File location(Ex: C:\documents and settings\csennes\File.csv)"

$MailboxAlias = read-host -prompt "Mailbox Identity/Alias Column Name"

import-csv "$FileLocation" | Foreach-Object{

Get-QADUser $_.$MailboxAlias | Set-QADUser -oa @{'msRTCSIP-UserEnabled'= $null; 'msRTCSIP-PrimaryHomeServer' = $null; 'msRTCSIP-InternetAccessEnabled'= $null; 'msRTCSIP-FederationEnabled' = $null; 'msRTCSIP-OptionFlags' = $null ; 'msRTCSIP-PrimaryUserAddress' = $null }

$user = Get-Recipient $_.$MailboxAlias

$user | ForEach-Object{

if ($user.RecipientType -eq "UserMailbox")

{

$Mailbox = Get-mailbox $user.DistinguishedName

$Parent = $Mailbox.database.parent

$Name = $Mailbox.database.name

$Database = "$parent\$name"

$Date = Get-Date

$Notes = $user.Notes

$NewNote = "$Notes ---- Disabled Mailbox by script on $Date -- Location was $Database"

Set-User -Identity $Mailbox.DistinguishedName -notes $NewNote

set-mailbox $Mailbox -EmailAddressPolicyEnabled $false -emailaddresses $null

Disable-Mailbox $Mailbox.DistinguishedName -confirm:$False

"$($user.Displayname) was a UserMailbox"

}

elseif ($user.RecipientType -eq "MailUser")

{

set-mailuser $Mailbox -emailaddresspolicy $false -emailaddresses $null

Disable-Mailuser -Identity $user.DistinguishedName -confirm:$False

"$($user.Displayname) was a MailUser"

}

elseif ($user.RecipientType -eq "MailContact")

{

Remove-MailContact -Identity $User.DistinguishedName -confirm:$False

"$($user.Displayname) was a MailContact"

}

else

{

"$($_.$MailboxAlias) does not have a Mail Object or Account cannot be found from the input data"

}

}

}


Viewing all articles
Browse latest Browse all 6937

Trending Articles