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