Register
: :
Login
Home
News
Forums
Scripts
User Groups
Resources
About
Forums
Search
Members
Unanswered
Active Topics
Forums
>
Using PowerShell
>
Active Directory
Disable user via powershell-Help needed
Last Post 12 Jan 2010 09:28 AM by
cameronove
. 4 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
Ash_Australia
New Member
Posts:5
28 Dec 2009 09:10 PM
Hi All,
I am new to powershell. I have a list of about 400 users which needs to be disabled. What I want to do (as per our process):-
1) Search for all account where samaccountname starts with HP
2) Disable them
3) Add zzz as prefix to the samaccountname ( e.g zzzhpabc)
4 And set the account expiry date to the current date.
After spending about half day on google i only managed to do below:-
Get-user -Resultsize Unlimited | Where-Object {$_.sAMAccountName -like "hp*"} | Select-Object Name, SamAccountName, Email, |export-csv c:\disablechange.csv
i also tried to pipe the below with the above command to add zzz but didnt worked.
Set-User -identity $_ -SamAccountName ($_.SamAccountName+ 'zzz')
Any help will be highly appreciated. Thanks
PS :- we do not have QA commandlets.
Cheers
Regards
Ash
Datacom
New Member
Posts:27
05 Jan 2010 03:51 PM
I have similar questions as well. Can anyone shed some light on how to do it with quest cmdlets. Thanks
cameronove
Basic Member
Posts:332
12 Jan 2010 09:16 AM
Try:
get-qaduser -includedproperties samaccountname,accountexpires -ldapfilter '(samaccountname=hp*)' | foreach{$_.samaccountname = "zzz$($_.samaccountname)";$_.accountexpires = (get-date);$_.commitchanges()}
cameronove
Basic Member
Posts:332
12 Jan 2010 09:18 AM
I edited my previous post but just in case you are getting this via email here is the corrected version
get-qaduser -includedproperties samaccountname,accountexpires -ldapfilter '(samaccountname=hp*)' | foreach{$_.samaccountname = "zzz$($_.samaccountname)";$_.accountexpires = (get-date);$_.commitchanges()}
cameronove
Basic Member
Posts:332
12 Jan 2010 09:28 AM
oops forgot to disable:
get-qaduser -includedproperties samaccountname,accountexpires -ldapfilter '(samaccountname=hp*)' | foreach{$_.samaccountname = "zzz$($_.samaccountname)";$_.accountexpires = (get-date);$_.commitchanges();disable-qaduser $_.distinguishedName}
You are not authorized to post a reply.
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Forums
>
Using PowerShell
>
Active Directory
Active Forums 4.3
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2