Forum Discussion
almarlibetario
Jun 03, 2019Brass Contributor
Account Expiration Default Value for "Never"
Hello Everyone, I hope somebody has an idea about my concern. I really need it badly as I have a client testing tomorrow. Anyways, the story is this, I need to create a script to update the a...
Kevin_Morgan
Jun 05, 2019Iron Contributor
To set Account Expiry Date as Never, you better use the Clear-ADAccountExpiration cmdlet or you need to set accountExpires attribute value to 0.
Clear-ADAccountExpiration -Identity 'UserName'
----or----
function Get-ADUserFN( [string]$samid=$env:username){ $searcher=New-Object DirectoryServices.DirectorySearcher $searcher.Filter="(&(objectcategory=person)(objectclass=user)(sAMAccountname=$samid))" $user=$searcher.FindOne() if ($user -ne $null ){ $user.getdirectoryentry() } } $user = Get-ADUserFN 'UserName'
$user.psbase.properties
$user.accountExpires = '0'
$user.SetInfo()
Note: I have not personally tested the above commands.
- almarlibetarioJun 25, 2019Brass Contributor
Thanks for this. Will definitely check this out.