Powershell script to delete folders under Winx

Santhosh B S 106 Reputation points
2023-05-18T11:53:48.4533333+00:00

Team,

I am looking for a script which should delete folders under C:\Users\BRXXXX\Appdata\Local\Micorsoft\Windows\winx\GROUP2 and GROUP3

and i need to retain the folders under winx for Administrator, defaultuser ,Default ,Public

Please help

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tushar Kumar 3,381 Reputation points MVP
    2023-05-18T14:09:31.7166667+00:00
    $foldersToDelete = @(
        "C:\Users\BRXXXX\AppData\Local\Microsoft\Windows\winx\GROUP2",
        "C:\Users\BRXXXX\AppData\Local\Microsoft\Windows\winx\GROUP3"
    )
    
    foreach ($folderPath in $foldersToDelete) {
        if (Test-Path $folderPath -PathType Container) {
            Write-Host "Deleting folder: $folderPath"
            Remove-Item -Path $folderPath -Force -Recurse
        } else {
            Write-Host "Folder not found: $folderPath"
        }
    }
    
    
    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.