Set user account expiry date

Source: Internet
Author: User

One useful feature of AD is that we can set an expiry date on an account-very useful for temporary workers or if we know someone is leaving at on particle date. the expiry date is stored in AD as the number of 100 nanosecond intervals since 1st January 1601-this is stored as a 64-bit integer

$date = Get-Date             $ou = "OU=England,DC=Manticore,DC=org"                        "`nMicrosoft"            $name = "UserA"            $exp = $date.Adddays(30)            Get-ADUser -Identity $name |            Set-ADAccountExpiration -DateTime $exp                        "`nAD provider"            $name = "UserB"            $dn = "cn=$name,$ou"            $exp = $date.Adddays(60).ToFileTime()            Set-ItemProperty -Path AD:\$dn  -Name accountExpires -Value $exp -Force                        "`nQuest"            $name = "UserC"            $exp = $date.Adddays(90)            Get-QADUser -Identity $name |            Set-QADUser -AccountExpires $exp                        "`nScript"            $name = "UserD"            $dn = "cn=$name,$ou"            $exp = $date.Adddays(120).ToShortDateString()            $user = [adsi]"LDAP://$dn"                        $user.AccountExpirationDate = $exp            $user.SetInfo()

In all cases I 've added a number of days to todays date to give the expiry date. it wocould be just as easy to specify a participant date.

The Microsoft cmdlets use Set-AdAccountExpiration and a datetime object

The Quest cmdlets and script accept a date in short date format.

The provider expects an integer-we can convert the date using ToFileTime () method

Notice the different attribute names between the script and the provider

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.