Script repository

Delete/purge user profile folder

Updated on: Jan 18, 2026, Views: 7678

Folders and profiles, User accounts

The scripts delete or purge a user’s profile folder. To execute the scripts, create a business rule, scheduled task or custom command configured for the User object type.

Script 1: Delete user profile folder

# Get profile folder path.
try
{
    $profilePath = $Context.TargetObject.Get("profilePath")
}
catch
{
    return
}

# Check whether the profile folder exists.
if(!(Test-Path -Path $profilePath))
{
    $Context.LogMessage("Incorrect profile path: $profilePath", "Error")
    return
}

# Delete the profile folder.
Remove-Item -Path $profilePath -Force -Recurse

Script 2: Purge user profile folder

# Get profile folder path.
try
{
    $profilePath = $Context.TargetObject.Get("profilePath")
}
catch
{
    $Context.LogMessage("No profile path specified for the user", "Warning")
    return
}

# Delete the contents of the profile folder.
$childItem = Get-ChildItem -Path $profilePath -Force
if($childItem -ne $NULL)
{
    $childItem | Remove-Item -Force -Recurse
}

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.