• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

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
0
Anestis Psomas
Asked:
Anestis Psomas
  • 8
  • 5
  • 2
  • +2
1 Solution
 
kiwistagCommented:
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.
0
 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
get-content d:\data\users.txt |get-aduser |set-aduser -enabled $false

- Rancy
0
 
Sushil SonawaneCommented:
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
0
 
suriyaehnopCommented:
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
0
 
Anestis PsomasSystem and Network AdministratorAuthor Commented:
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 .
0
 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
The one i gave works good with the txt .... maybe you can test anyone with just few users to be sure rather than work on All :)

get-content d:\data\users.txt |get-aduser |set-aduser -enabled $false

- Rancy
0
 
Anestis PsomasSystem and Network AdministratorAuthor Commented:
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
0
 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
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
0
 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
You can use -Server "FQDN of the DC"

- Rancy
0
 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
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
0
 
Anestis PsomasSystem and Network AdministratorAuthor Commented:
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
0
 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
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
0
 
Anestis PsomasSystem and Network AdministratorAuthor Commented:
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
0
 
Manpreet SIngh KhatraSolutions Architect, Project LeadCommented:
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
0
 
suriyaehnopCommented:
Can you post your txt file? so that I can try with my enviroment
0
 
Anestis PsomasSystem and Network AdministratorAuthor Commented:
I create a csv file and it works perfectly !! Thanks for all your help guys and especially rancy
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 8
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now