Get password reset info for users with Windows PowerShell script

1 Mar

http://www.techrepublic.com/blog/networking/get-password-reset-info-for-users-with-windows-powershell-script/5371?tag=nl.e102

Function get-pwdset{
Param([parameter(Mandatory=$true)][string]$user)
$use = get-aduser $user -properties passwordlastset,passwordneverexpires

If($use.passwordneverexpires -eq $true)

{
 write-host $user "last set their password on " $use.passwordlastset  "this account has a non-expiring password" -foregroundcolor yellow
}

Else

{
$til = (([datetime]::FromFileTime((get-aduser $user -properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed"))-(get-date)).days
if($til -lt "5")
{
 write-host $user "last set their password on " $use.passwordlastset "it will expire again in " $til " days" -foregroundcolor red
}
else
{
 write-host $user "last set their password on " $use.passwordlastset "it will expire again in " $til " days" -foregroundcolor green
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: