Solved

PowerShell Script to disable a list of users

Posted on 2011-09-07
5
911 Views
Last Modified: 2012-05-12
I need a powershell script to read a list of users from a txt file, disable the user account and change the description of each user.

Any good ideas?
0
Comment
Question by:LindyS
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Krzysztof Pytko earned 500 total points
ID: 36494670
I'm not PowerShell expert, but I can provide you script for that in 2 steps :)

On XP/2003/2008 use Quest PowerShell module for AD (can be downloaded from http://www.quest.com/powershell/activeroles-server.aspx) and use this structure

Get-Content <path-to-txt-file-with-users> | %{ Set-QADUser $_ -Description "Description Text" }
Get-Content <path-to-txt-file-with-users> | %{ Disable-QADUser $_ }

on 7/2008 R2 with AD modules use

Get-Content <path-to-txt-file-with-users> | %{ Set-ADUser $_ -Description "Description Text" }
Get-Content <path-to-txt-file-with-users> | %{ Disable-ADAccount $_ }

Please test it on small users part.

Regards,
Krzysztof
0
 
LVL 3

Author Comment

by:LindyS
ID: 36494774
Thanks...That looks like it would work, but it appears I am not able to modify users with a script.

Disable-QADUser : Access is denied.
At C:\scripts\Disable.ps1:18 char:56
+ Get-Content "C:\temp\userlist.txt" | %{ Disable-QADUser <<<<  $_ }
+ CategoryInfo          : NotSpecified: (:) [Disable-QADUser], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.DisableUserCmdlet
0
 
LVL 3

Author Closing Comment

by:LindyS
ID: 36494778
This would work, if I were able to modify users with a script.
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 36494874
OK, I missed something, let's try with

Get-Content <path-to-txt-file-with-users> | %{ Get-QADUser $_ | Disable-QADUser }

I'm sorry.
Krzysztof
0
 
LVL 39

Expert Comment

by:Krzysztof Pytko
ID: 36494876
OK, I missed something, let's try with

Get-Content <path-to-txt-file-with-users> | %{ Get-QADUser $_ | Disable-QADUser }

I'm sorry.
Krzysztof
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now