Skip to content

Instantly share code, notes, and snippets.

@nishanc
Last active January 14, 2024 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishanc/aabec75ad95579d7b9f02a4eaf9e6994 to your computer and use it in GitHub Desktop.
Save nishanc/aabec75ad95579d7b9f02a4eaf9e6994 to your computer and use it in GitHub Desktop.
# WARNING: This script will delete everything in Downloads, Pictures, Videos, Documents\PowerShell folders for the specified user and the D: drive.
# Use it at your own risk.
# Specify the user's profile folder
$userProfile = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
# Specify the folders to delete for the user
$userFoldersToDelete = @("Downloads", "Pictures", "Videos", "Documents\PowerShell")
# Specify the drive to delete
$driveLetter = "D:"
# Confirm the deletion of user folders and the drive
$confirmation = Read-Host -Prompt "Are you sure you want to delete everything in Downloads, Pictures, Videos, and Documents\PowerShell folders for user $env:USERNAME and on drive $driveLetter? (Type 'YES' to confirm)"
if ($confirmation -eq 'YES') {
# Delete user folders
foreach ($folder in $userFoldersToDelete) {
$folderPath = Join-Path $userProfile $folder
try {
Get-ChildItem -Path $folderPath -Recurse | ForEach-Object {
Remove-Item $_.FullName -Force
}
Write-Host "Deletion completed for $folderPath"
} catch {
Write-Host "Error: $_"
}
}
# Delete the entire D: drive
try {
Get-ChildItem -Path $driveLetter -Recurse | ForEach-Object {
Remove-Item $_.FullName -Force
}
Write-Host "Deletion completed for $driveLetter"
} catch {
Write-Host "Error: $_"
}
} else {
Write-Host "Operation canceled."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment