Last active
January 14, 2024 17:01
-
-
Save nishanc/aabec75ad95579d7b9f02a4eaf9e6994 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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