Solved

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

Posted on 2011-02-16
13
2,589 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Is Your AD Toolbox Looking More Like a Toybox?

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.

 

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 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 71

Expert Comment

by:Chris Dent
ID: 34914084

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

Chris
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
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…

740 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