Solved

PowerShell Script to disable a list of users

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
A brief introduction to what I consider to be the best editor for PowerShell.
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

10 Experts available now in Live!

Get 1:1 Help Now