Solved

powershell script to extend the expiration date of user account to april 1st, 2011

Posted on 2011-02-16
13
2,518 Views
Last Modified: 2012-05-11
Hi All,

I need a powershell script to change the expiration date of user account to april 1st, 2011. we are running 2008 R2 with active directory module loaded.

Pleaes advise.

Thanks
0
Comment
Question by:fireburn11
  • 6
  • 4
  • 3
13 Comments
 
LVL 16

Expert Comment

by:Dale Harris
ID: 34910052
Try this:

get-qaduser | set-qaduser -oa @{accountExpires = '129462012000000000'}

You must also have the Quest AD CMDlets installed:
http://www.quest.com/powershell/activeroles-server.aspx

HTH,

Dale Harris
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 34910406
You know, Set-QADUser has an -AccountExpires parameter. See:
Get-Help Set-QADUser -Parameter AccountExpires

Open in new window

It should be a bit easier to use than the date string for ObjectAttributes :)

Chris
0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 34910638
Thanks, Chris.  I didn't know if there was a way to set it easier.  

Dale
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:fireburn11
ID: 34911301
thanks guys , but sqduser is only availabe with quest add-in installed, which i dont have...
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 34911325
Ah shame, still, 2008 R2... MS AD Module?

If so:
Import-Module ActiveDirectory

Set-ADUser "UserID" -AccountExpirationDate $(Get-Date "18/02/2011")

Open in new window

Chris
0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 34911387
Don't you mean:

Import-Module ActiveDirectory

Set-ADUser "UserID" -AccountExpirationDate $(Get-Date "1/04/2011")


?

Also, Fireburn, if you haven't checked out Quest CMDlets, I would really recommend it. :)

DH
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 34911398
Oh yeah, April, missed that bit :)

So yes, that'd be better :)

Chris
0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 34911408
So, in regards to this question at least, I would say we broke even :)

Dale
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 34911437
lol :)

Chris
0
 

Author Comment

by:fireburn11
ID: 34911717
thanks guys. However, instead of doing bulk users which is over 3000 users. I decided to do 20 users at a time just to be safe.
I have put user's samaccountname in a text file,

i need powershell script to read in the text file then do set-aduser -accountexpirationdate "4/1/2011"

Any idea how to do that?

Thanks
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 34911727
Yep, nice and easy:
Get-Content YourFile.txt | ForEach-Object {
  Set-ADUser $_ -AccountExpirationDate $(Get-Date "01/04/2011")
}

Open in new window

Modify date format as appropriate :)

Chris
0
 

Author Comment

by:fireburn11
ID: 34911865
Thanks Chris.

question on this line:Set-ADUser $_ -AccountExpirationDate $(Get-Date "01/04/2011")

can i simply do -accountexpirationdate "4/1/2011" or it has to be $(get-date "01/04/2011")?
if so, please explain..
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 34914084

It should take "4/1/2011" and handle it for you.

Chris
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
A procedure for exporting installed hotfix details of remote computers using powershell
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

831 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