concept whose password in category powershell

appears as: whose passwords, whose password
Learn PowerShell Scripting in a Month of Lunches

This is an excerpt from Manning's book Learn PowerShell Scripting in a Month of Lunches.

6.5.1. Emailing users whose passwords are about to expire

This is a great example, and it’s one we’re going to put some code to later in this book. Say that you wanted to send a quick email reminder to users whose passwords were about to expire in a day or two. What’s involved there?

You’d need to start by getting a list of users who have expiring passwords—that is, whose accounts aren’t disabled and who don’t have a “password does not expire” setting. You’d probably then need to calculate exactly when their password does expire, and filter out anyone whose password wasn’t expiring within whatever range you cared about. You’d then send them all an email and perhaps log that information to a file for diagnostic purposes.

  • The next block calculates some date values so that it knows when tomorrow is. This is so it can remind only users whose passwords are about to expire soon, and not spam everyone who has a password expiration coming up a couple of months from now. Our concern is that this is more or less a dedicated task; in the spirit of toolmaking, we’d have created a standalone function to perform this task, and had it return whatever bits of data we needed. Here’s that block of code:
    $start = [datetime]::Now
    $midnight = $start.Date.AddDays(1)
    $timeToMidnight = New-TimeSpan -Start $start -end $midnight.Date
    $midnight2 = $start.Date.AddDays(2)
    $timeToMidnight2 = New-TimeSpan -Start $start -end $midnight2.Date