Solved

PowerShell Script to disable a list of users

Posted on 2011-09-07
5
921 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Here's a look at newsworthy articles and community happenings during the last month.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

617 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