PowerShell Script to disable a list of users

LindyS
LindyS used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Active Directory Engineer
Top Expert 2012
Commented:
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

Author

Commented:
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

Author

Commented:
This would work, if I were able to modify users with a script.
Krzysztof PytkoSenior Active Directory Engineer
Top Expert 2012

Commented:
OK, I missed something, let's try with

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

I'm sorry.
Krzysztof
Krzysztof PytkoSenior Active Directory Engineer
Top Expert 2012

Commented:
OK, I missed something, let's try with

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

I'm sorry.
Krzysztof

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial