Last active
December 20, 2018 14:02
-
-
Save miketweaver/feefa63944e6980a01cae45ffd8491cd to your computer and use it in GitHub Desktop.
Windows VM Cleanup before Snapshot
This file contains hidden or 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
| REM # ----------------------------------------------------------------- | |
| REM # This requires ultradefrag, and sdelete installed. | |
| REM # cinst ultradefrag sysinternals -y | |
| REM # run as Admin | |
| REM # ----------------------------------------------------------------- | |
| net stop wuauserv | |
| rmdir /S /Q C:\Windows\SoftwareDistribution\Download | |
| mkdir C:\Windows\SoftwareDistribution\Download | |
| net start wuauserv | |
| rd /s /q %systemdrive%\$RECYCLE.BIN | |
| udefrag.exe --optimize --repeat C: | |
| %SystemRoot%\System32\reg.exe ADD HKCU\Software\Sysinternals\SDelete /v EulaAccepted /t REG_DWORD /d 1 /f | |
| sdelete64.exe -q -z C: |
This file contains hidden or 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
| # ----------------------------------------------------------------- | |
| # This requires ultradefrag, and sdelete installed. | |
| # cinst ultradefrag sysinternals -y | |
| # run as Admin | |
| # ----------------------------------------------------------------- | |
| # @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://gist.githubusercontent.com/miketweaver/feefa63944e6980a01cae45ffd8491cd/raw/cleanup.ps1'))" | |
| # ----------------------------------------------------------------- | |
| # Cleanup Unnecessary Files | |
| Stop-Service wuauserv | |
| Remove-Item -Recurse -ErrorAction SilentlyContinue C:\Windows\SoftwareDistribution\Download\* | |
| Start-Service wuauserv | |
| Get-ChildItem -Path 'C:\$Recycle.Bin' -Force | Remove-Item -Recurse -ErrorAction SilentlyContinue | |
| # Defrag | |
| & udefrag.exe --optimize --repeat C: | |
| # Clear Freespace with 0s | |
| New-Item -Path "HKCU:\Software\Sysinternals" -Name SDelete -Force | |
| Set-ItemProperty -Path HKCU:\Software\Sysinternals\SDelete -Name EulaAccepted -Value 1 -Type DWord | |
| & sdelete64.exe -q -z C: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment