Have any questions

Delete Unwanted Windows Users’ Profile from the System

Have multiple users been moved from or left your organization but their user profiles are still active? With this script, you can delete User Profiles that have remained inactive for X number of days

Syntax

$d = (get-date).AddDays(-30) 

$prof = @(ls c:\users -Exclude “Administrator”) 

$tobedeleted=@() 

foreach($i in $prof){ 

if($i.lastwritetime –lt $d){ 

$tobedeleted += $i } 

} 

$tobedeleted 

Download Full Script

Purpose:Administrator can delete windows user profiles that are older than X number of Days. Days can be modified in the script as per need, deleted logs would be saved under the path defined in the script
Modification:Administrator can modify the script as per their requirements
Type:PowerShell Script (ps1)  
Compatibility:Windows
Tags:-
Reference link:

https://gallery.technet.microsoft.com/scriptcenter/Remove-UserProfile-Remove-96e27a3b