Solved

PowerShell Script to disable a list of users

Posted on 2011-09-07
5
912 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

910 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

16 Experts available now in Live!

Get 1:1 Help Now