Set the expiration date for an Active Directory account.
Syntax Set-ADAccountExpiration [-Identity] ADAccount [-TimeSpan] TimeSpan [-DateTime] DateTime [-AuthType {Negotiate | Basic}] [-Credential PSCredential] [-Partition string] [-PassThru] [-Server string] [-Confirm] [-WhatIf] [CommonParameters] Key -AuthType {Negotiate | Basic} The authentication method to use: Negotiate (or 0), Basic (or 1) A Secure Sockets Layer (SSL) connection is required for Basic authentication. -Credential PSCredential A user account that has permission to perform this action. The default is the current user unless the cmdlet is run from an AD PowerShell provider drive in which case the account associated with the drive is the default. "User64" or "Domain01\User64" or a PSCredential object. -DateTime DateTime The expiration time for the account, set using a DateTime value. Time is assumed to be in local time unless otherwise specified. When a date is not specified, the date is assumed to be the current date. When a time value is not specified, the time is assumed to be midnight local time (i.e. the very start of the day 12:00:00 am) Examples "2:54 PM" "2:54:48 PM" "4/12/2012" "4/12/2012 2:54 PM" "Monday, April 12, 2012" "Monday, April 12, 2012 2:54:48 PM" "Monday, April 12, 2012 2:54 PM" Greenwich Mean Time (GMT) /RFC1123 standard: "Mon, 12 Apr 2012 21:54:48 GMT" Coordinated Universal Time (UTC): "2012-04-12T14:54:48.0000000" -Identity ADAccount Specify an AD domain object by providing one of the following values. (The identifier in parentheses is the LDAP display name for the attribute.) Distinguished Name Example: DC=Helvetia,DC=corp,DC=SS64,DC=com GUID (objectGUID) Example: 599c4d2e-f72d-4d20-8a78-030d69495f20 Security Identifier (objectSid) Example: S-1-5-21-5165297888-301467370-576410423-1803 Security Accounts Manager (SAM) Account Name (sAMAccountName) Example: Helvetia The cmdlet searches the default naming context or partition to find the object. If two or more objects are found, the cmdlet returns a non-terminating error. This parameter can also get this object through the pipeline or you can set this parameter to an object instance. -Partition string The distinguished name of an AD partition. The distinguished name must be one of the naming contexts on the current directory server. The cmdlet searches this partition to find the object defined by the -Identity parameter. The following two examples show how to specify a value for this parameter. -Partition "CN=Configuration,DC=Europe,DC=Test,DC=SS64,DC=com" -Partition "CN=Schema,CN=Configuration,DC=Europe,DC=Test,DC=SS64,DC=com" In many cases, a default value will be used for -Partition if no value is specified. -PassThru Return the new or modified object. By default (i.e. if -PassThru is not specified), this cmdlet does not generate any output. -Server string The AD Domain Services instance to connect to, this may be a Fully qualified domain name, NetBIOS name, Fully qualified directory server name (with or without port number) or AD Snapshot instance. Examples: demo.SS64.com demo demoDC02.demo.ss64.com demoDC02.demo.ss64.com:3268 -TimeSpan TimeSpan Set the account to expire at the end of the TimeSpan time interval. The time interval will begin at the current time. Format: [-]D.H:M:S.F where: D = Days (0 to 10675199) H = Hours (0 to 23) M = Minutes (0 to 59) S = Seconds (0 to 59) F= Fractions of a second (0 to 9999999) Note: Time values must be between -10675199:02:48:05.4775808 and 10675199:02:48:05.4775807 Examples: Set the time to 2 days -TimeSpan "2" Set the time span to the previous 2 days -TimeSpan "-2" Set the time to 4 hours -TimeSpan "4:00" -Confirm Prompt for confirmation before executing the command. -WhatIf Describe what would happen if you executed the command, without actually executing the command. CommonParameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable, -OutBuffer -OutVariable.
Set-ADAccountExpiration sets the expiration time for a user, computer or service account.
To specify an
exact time, use the -DateTime parameter.
To specify a time period from the current time, use the -TimeSpan parameter.
Examples
Sets the account with SamAccountName: TommyEllis to expire on the 18th of October, 2015:
PS C:\> Set-ADAccountExpiration KarenBe -DateTime "10/18/2015"
Set the expiration date of all the user accounts who are a member of the group: grp_Legal_boston to 60 days from now.
PS C:\> Get-ADGroupMember grp_Legal_boston | where {$_.objectClass -eq "user"} | Set-ADAccountExpiration -timespan 60.0:0
“This is not the end. It is not even the beginning of the end. But it is, perhaps, the end of the beginning” ~ Winston Churchill
Related PowerShell Cmdlets:
Clear-adAccountExpiration - Clear the expiration date for an AD account.