Solved

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

Posted on 2011-02-16
13
2,428 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Synchronize a new Active Directory domain with an existing Office 365 tenant
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now