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://learn.microsoft.com/en-us/troubleshoot/windows-server/user-profiles-and-logon/delete-user-profile