Skip to content

Instantly share code, notes, and snippets.

@virtualhobbit
Last active June 30, 2020 12:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save virtualhobbit/de0cb84fd05b94c4cc6d61098fda81d9 to your computer and use it in GitHub Desktop.
Save virtualhobbit/de0cb84fd05b94c4cc6d61098fda81d9 to your computer and use it in GitHub Desktop.
$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