Last active
June 30, 2020 12:01
-
-
Save virtualhobbit/de0cb84fd05b94c4cc6d61098fda81d9 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
$ErrorActionPreference = "Stop" | |
$url = "https://download.sysinternals.com/files" | |
$zip = "SDelete.zip" | |
$exe = "sdelete64.exe" | |
$arg = "-z c: /accepteula" | |
# Get SDelete | |
Invoke-WebRequest -Uri ($url + "/" + $zip) -OutFile C:\$zip | |
# Unzip it | |
Expand-Archive -LiteralPath "C:\$zip" -DestinationPath C:\ -Confirm:$false | |
# Run SDelete | |
Try | |
{ | |
Start-Process C:\$exe -ArgumentList $arg -PassThru -Wait -ErrorAction Stop | |
} | |
Catch | |
{ | |
Write-Error "Failed to run SDelete" | |
Write-Error $_.Exception | |
Exit -1 | |
} | |
# Delete files | |
[Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | |
$source = [IO.Compression.ZipFile]::OpenRead("C:\$zip") | |
$entries = $source.Entries | |
ForEach ($file in $entries) | |
{ | |
Remove-Item -Path C:\$file -Confirm:$false | |
} | |
$source.Dispose() | |
Remove-Item C:\$zip -Confirm:$false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment