Today will show you shor PS script which will remove specified file in all user profiles in specified location.
Script has a few lines:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$usersPath = "C:\Users" #get users lists $users = Get-ChildItem -Path $usersPath -Directory #search for file in every userprofile foreach ($user in $users) { $desktopPath = Join-Path -Path $user.FullName -ChildPath "Desktop\testFile.txt" if (Test-Path $desktopPath) { #remove file Remove-Item $desktopPath -Force Write-Host "Removed'testFile.txt'from user desktop: $($user.Name)" } } |