Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Compare pwdLastSet

$
0
0

We're trying to compare the user's pwdLastSet date to a certain date and would like the output to contain only those users who's pwdLastSet is before 10/15/14.

There are 314 users and after pulling these accounts from AD, a compare is done on the dates similar to this:

$cutoffdate = (Get-Date 10/15/14).ToShortDateString()

Foreach ($user in $allUsers)

{

     $lastChanged = ($user.passwordLastSet).ToShortDateString()

     if ($lastChanged -lt $cutoffdate)

     {

     $usersNotChanged += $user

     }

}

$usersNotChanged | ft Name, passwordLastSet

Even though this provides a list of about 24 users, when you look at the pwdLastSet some of the dates are before 10/15/14 and some are after.  When I use -gt, it lists the other 290 users and again some have dates before and after 10/15/14. 

Is there a better way to compare the dates?  Again, we'd like to get a list of users who haven't changed their passwords before a particular date.


Viewing all articles
Browse latest Browse all 6937

Trending Articles