This PowerShell script sample shows how to get managed accounts or expired managed accounts in SharePoint 2010.
Sometimes users want to list all managed accounts or accounts to expire within five days. This script is to achieve that purpose.
Step 1: Right click the script and select Run with PowerShell.
Step 2: After that, it will display a Windows PowerShell console.

Here are some code snippets for your reference.
$PasswordExpiredDate = $item.PasswordExpiration
$Tim = New-TimeSpan -Start $CurrentDate -End $PasswordExpiredDate
#Get expired accounts
If($Tim.Days -le 0)
{
$ExpiredAccount += $item
}
#Get accounts to expire within five days
If($Tim.days -eq 5)
{
$ExpiredFive += $item
}
$PasswordExpiredDate = $item.PasswordExpiration $Tim = New-TimeSpan -Start $CurrentDate -End $PasswordExpiredDate #Get expired accounts If($Tim.Days -le 0) { $ExpiredAccount += $item } #Get accounts to expire within five days If($Tim.days -eq 5) { $ExpiredFive += $item }
Windows Server 2008 R2