PowerShell Get Local Account Password Age of Remote computer

The small function below will allow you to get the age of the password of an account on a remote computer:

Function Get-LocalPasswordAge([string]$server,[string]$user)<br /> {<br /> if (($user -ne "") -and ($server -ne "")){[Math]::Round(([ADSI]"WinNT://$server/$user").PasswordAge[0] /86400)}<br /> }

As you can see, the heart of this uses the ADSI provider for PowerShell, which means there aren’t any other cmdlets required.