Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Active Directory Set User Accounts to Expire

Posted on 2014-02-01
14
Medium Priority
?
2,453 Views
Last Modified: 2014-02-04
I have 300 users within a Location in Ad that I need to set to expire at the end of FEB. 2014.  Is there a script to od this with.  I found two but there sytnaxes show as invalid:

Set-ADAccountExpiration [-Identity] gclinch  [-DateTime] "02/28/2014 5:00:00 PM"

"Error stats Set-ADAccountExpiration is not valid"

Set-ADUser gclinch -AccountExpirationDate "02/28/2014 5:00:00 PM"

"Error stats Set-ADUser is not valid"
0
Comment
Question by:Twhite0909
[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
  • 5
  • 3
14 Comments
 
LVL 18

Expert Comment

by:Steven Harris
ID: 39826566
Which console are you running this in?  This a PowerShell command.

From PowerShell, try the following syntax:

Set-ADAccountExpiration gclinch -DateTime "02/28/2014 5:00:00 PM"

Open in new window


You should also make sure the AD Modules are loaded in the "Windows Features" pane if you are running remotely, or if they were disabled previously on the server.
0
 

Author Comment

by:Twhite0909
ID: 39826626
I am using  "Active Directory Module for powershell" located on my domain controller.  I also tried running the commands fro Exchange 2010 Shell

Now in Ad Module for Poweshell I ran your command and got the following error:

Set-ADAccountExpiration [-Identity] gclinch  [-DateTime] "02/28/2014 5:00:00 PM"

The term 'Set-ADAccountExpiration' is not recognized as the name of a cmdlet, function, script file,
0
 
LVL 18

Expert Comment

by:Steven Harris
ID: 39826649
What server are you running?
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 18

Expert Comment

by:Steven Harris
ID: 39826656
Try the following commands:

Add-WindowsFeature RSAT-AD_PowerShell

Open in new window


Import-Module ActiveDirectory

Open in new window

0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 39826680
Seems that your module in not loading properly. Can you try the following command...
get-module

The command above will tell you if the activedirectory module has been installed. based on the errors you are getting it has not installed correctly.

Aside from that you can do this very easily via the GUI. See the screenshot below. Simply hold shift and select all of the users in an OU, right click Properties, click the account tab and set all accounts to expire on a speciifc data.

Account Expires GUI
Account Expires
Will.
0
 

Author Comment

by:Twhite0909
ID: 39829847
After running Get-Module I see the following:


ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Manifest   ActiveDirectory           {Set-ADOrganizationalUnit, Get-ADDomainControllerPasswordReplicationPoli...
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 39829881
Ok well the ActiveDirectory module appears to be loaded into the session. Did you try the GUI suggestion in my previous post? Does that work for you? Have you checked the event viewer to see if there are any issues in regards to Windows Powershell?

Will.
0
 

Author Comment

by:Twhite0909
ID: 39829899
OK I got the AD module to import and its now accepting commands., So the cmd:


Set-ADAccountExpiration "user" -DateTime "02/28/2014 5:00:00 PM"

Has just worked successfully.  Now my bigger questions.  Is their a way to run this command against an entire OU in order to set all users within that OU to expire on that date>

Also we use Password Manager from Dell that allows a user that if their PW expired and they need it reset they can go to this Tools weblink and reset themselves.  If I set an Account o expire could they technically use this tool to reset their PW and they have access again or would it require an ADMIN to reset the Expiration date on their account in order for the account to have log on access?

Thanks for all your help guys I really appreciate it.
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 39829929
You can use the syntax below to accomplish this...

get-aduser -fliter * -searchbase "OU=testou,dc=domain,dc=com" | Set-ADAccountExpiration "user" -DateTime "02/28/2014 5:00:00 PM"

Open in new window


That should do it.

Will.
0
 

Author Comment

by:Twhite0909
ID: 39830118
I dont think it likes the -Filter or -Searchbase?


PS C:\Users\WhiteT> get-aduser -filter * -searchbase OU=charlotte,dc=ad dc=local | Set-ADAccountExpiration "user" -DateTime "02/03/2014 5:00:00 PM"

et-ADUser : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'SearchBase'. Specified method is not supported.

At line:1 char:33
+ get-aduser -filter * -searchbase <<<<  OU=charlotte,dc=ad dc=local | Set-ADAccountExpiration "user" -DateTime "02/03/2014 5:00:00 PM"
    + CategoryInfo          : InvalidArgument: (:) [Get-ADUser], ParameterBind
   ingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.
   Management.Commands.GetADUser
0
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 2000 total points
ID: 39830136
This worked for me in my test lab with no issues.

See the below syntax i used to accomplish this.
get-aduser -Filter * -SearchBase "ou=testou,dc=upgrade,dc=local" | Set-ADAccountExpiration -DateTime "02/03/2014 5:00:00 PM"

Open in new window


The above should work for you.

Will.
0
 

Author Comment

by:Twhite0909
ID: 39830172
I am on my domain controller. I launch Active Directory Module for Windows Powershell and run the below cmd:

get-aduser -Filter * -SearchBase ou=charlotte,dc=ad,dc=local | Set-ADAccountExpiration -DateTime "02/03/2014 5:00:00 PM"

Charlotte is the OU AD.local is th domain.  It comes back every time with  " Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'SearchBase'. Specified method is not supported."  Is there something wrong with module for Powershell and AD?
0
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 39830259
It is possible as you were encountering issues before when the module was installed. Have you tried putting "qoutes" around the "ou=testou...."?

The command i have posted above earilier worked completely fine on my DC only using the Active Directory Module.

Will.
0
 

Author Comment

by:Twhite0909
ID: 39830480
OK The quotes got me 1 step further sorry I thought i removed quotes from examples.  However now it says  "Get-ADUser : Directory Object Not Found

Now my OU I'm trying to reach is under some other OUs  its location in ADUC is

AD.LOCAL/Locations/RSG/Charlotte

Do I need another parameter to drill down?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

688 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