header image

Setting local account expiry dates

Posted by: | July 15, 2011 | No Comment |

Setting expiry dates on AD accounts is a common occurrence and is well documented. Setting expiry dates on local accounts is also possible

$user = [adsi]"WinNT://./Test1, user"            
            
$expirydate = (Get-Date).AddDays(2)            
            
$user.Put("AccountExpirationDate", $expirydate)            
$user.SetInfo()            
            
$user.RefreshCache()            
            
$user | Format-List *

This uses the WinNT (remember its case sensitive) ADSI connector to get a local account.  We then set the AccountExpirationDate property to the desired date – in this case two days from now.

Quick call to SetInfo() and we are done

under: IT Security, PowerShell and Active Directory, Windows 7, Windows Server 2008, Windows Server 2008 R2