Link to home
Start Free TrialLog in
Avatar of Anestis Psomas
Anestis Psomas

asked on

How to Disable multiple users in Exchange 2007

Hello,


I have an Exchange 2007 in hosted mode and one of my organizations has about 15000 users. I want to disable a large number of them .About 9000 of them.  I have the usernames of the users i want to disable. Any help of how to do it more easy ?

Thanks a lot
Avatar of kiwistag
kiwistag
Flag of New Zealand image

In what form do you have them in? A list by username?
There are ways to do it in Exchange Powershell. Usually you'll require the (LDAP/OU, sorry - mind blank) format like:
CN=Firstname Surname, OU=Staff,DC=domain,DC=lan.
I think you can do it by sAMAccountName too.
Avatar of Manpreet SIngh Khatra
get-content d:\data\users.txt |get-aduser |set-aduser -enabled $false

- Rancy
Refer the following link

(http://www.manageengine.com/products/ad-manager/disable-delete-active-directory-exchange-mailbox.html)

It's might help you. Free trail version also available.
I used this cmdlet:

Import-Module -Name ActiveDirectory
$users = Import-Csv C:\PS\DeleteUser.csv

Foreach ($user in $users)
{
#The header of CSV file must contain "alias","email","company","Resigned OU
Get-DistributionGroup | where { (Get-DistributionGroupMember $_ | foreach { $_.primarysmtpaddress } ) -contains $user.email } | Remove-DistributionGroupMember -member $user.email -Confirm:$false
Disable-Mailbox -Identity $user.alias -Confirm:$false
Set-ADUser -Identity $user.alias -Enabled:$false -AccountExpirationDate (Get-Date).AddDays(1) -Company ('EX'+'-'+$user.company) -Confirm:$false
Get-ADUser -Identity $user.alias | Move-ADObject -Targetpath $user.ou -Confirm:$false

Open in new window


This script will:
Remove the user from any distribution list
Disable the mailbox
Set the AD account to be disabled and Account Expiry
Move the user to Resigned Organizational Unit

You do require following powershell module:

Exchange Snapin
Active Directory module
Avatar of Anestis Psomas
Anestis Psomas

ASKER

Thanks for all your answers.

The only thing i have is a txt with the email accounts .

I will have a look for all your solutions you gave me and see what fits me .
ASKER CERTIFIED SOLUTION
Avatar of Manpreet SIngh Khatra
Manpreet SIngh Khatra
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Rancy the command you gave me works but i take an error that says " Cannot find an object with this identity xxx@mail.com under DC : xxx " 

This error is correct as the command looks for domain names and not mailboxes .

Any ideas ?

Thanks
Is it happening for all users or just few accounts ?

If for few accounts you have to make sure they their information is correct ..

- Rancy
You can use -Server "FQDN of the DC"

- Rancy
Set-ADUser
http://ss64.com/ps/set-aduser.html

Set-ADUser
http://technet.microsoft.com/en-us/library/ee617215.aspx

Server
Specifies the Active Directory Domain Services instance to connect to, by providing one of the following values for a corresponding domain name or directory server. The service may be any of the following: Active Directory Lightweight Domain Services, Active Directory Domain Services or Active Directory Snapshot instance.
Domain name values:
Fully qualified domain name
Examples: corp.contoso.com
NetBIOS name
Example: CORP

- Rancy
Hi

As i said the problem is that i have only a txt file with the mailboxes.

Lets take for example the mailbox 1stop@xxx.gr
This mailbox has a username in the domain 1stop_xxx

So with the command we try we get an error that i thing its normally to appear because it read's the txt , it gets the mail 1stop@xxx.gr and its searching in the domain for account 1stop@xxx.gr and that is wrong.

Am i right ?

Thanks
Yes ... if you have multiple domains you need to run there ...... reason being that Domain partition are different so one domain object cannot be modified from a different domain .... maybe until the account we use to run could be Enterprise with elevated rights :)

For this you could try with the -Credential switch.

- Rancy
Perfect it works!! But now i have another problem

In my txt file each email is in a different line

When i try to run the command with more than 1 email in the txt file i get an error

Can i do something for this ?

Thanks a lot
Hehehehe ... thats always there one gone one in .... no worries :)
Hope there isnt extra spaces in there ?

Whats the error ? .... did you try putting the data in Excel and try that ?

- Rancy
Can you post your txt file? so that I can try with my enviroment
I create a csv file and it works perfectly !! Thanks for all your help guys and especially rancy