How to get managed accounts or expired managed accounts in SharePoint 2010(PowerShell)

Introduction

This PowerShell script sample shows how to get managed accounts or expired managed accounts in SharePoint 2010.

Scenarios

Sometimes users want to list all managed accounts or accounts to expire within five days. This script is to achieve that purpose.

Script

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.

PowerShell
Edit|Remove
$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 
}

Prerequisite

Windows Server 2008 R2