A friend asked for some help on writing a script that would delete all the users profile folders. Ie

C:\Users Data\%USER NAME%\Profile

So the real data would like something like that

C:\Users Data\Timmy\Profile
C:\Users Data\Tommy\Profile
C:\Users Data\Johnny\Profile

This is the script I pulled together, needs some error checking but gets the job done.

$folders = get-childitem  C:\sitename\ -Recurse | Where-Object {$_.psiscontainer -eq $True} | Where-Object {$_.name -eq "profile"} 

foreach ($f in $folders){
    Write-Host "deleteing " $f.FullName
    remove-item -Path $f.FullName
    }

PowerShell

Advertisements