Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-16
13
Medium Priority
?
2,779 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 71

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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

Author Comment

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

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 71

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 71

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 71

Accepted Solution

by:
Chris Dent earned 2000 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 71

Expert Comment

by:Chris Dent
ID: 34914084

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

Chris
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

886 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