Solved

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

Posted on 2011-02-16
13
2,548 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Computer account cleanup 90 128
O365 Directory Sync errors 3 22
Start-VM 3 18
Powershell query 1 22
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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