Delete Unused user Profiles on local machine (PowerShell)

Introduction

This PowerShell script shows how to delete unused user profiles on local machine.

Scenarios

Sometimes, one user may have not logged for three months. However, in order to save space, we need to delete those profiles.

Script

Step1: Run the script in the Windows PowerShell Console. Type the command: <Script Path> at the prompt.
For example, type C:\Script\Removeunusedfolder.ps1
This is shown in the following figure:
The result is shown in the following figure:
Note This script just remove three-month unused user profiles. If you want remove other time, you can change $PeriodDays  to any days you want.
 
Here are some code snippets for your references
PowerShell
Edit|Remove
If(Test-Path -Path "C:\Documents and Settings\") 
{ 
    $UserParentFolder = "C:\Documents and Settings\" 
} 
  
If(Test-Path -Path "C:\Users\") 
{ 
    $UserParentFolder = "C:\Users\" 
} 
#set unused days 
$PeriodDays = 90  
  
$Result = @() 
#get all user folders 
$userFolders = Get-ChildItem -Path $UserParentFolder

Prerequisite

Windows XP, 7 or 8