Created
June 25, 2020 11:30
-
-
Save AndreasHassing/1760dfed9f39b33ec80bbedea88ff5a2 to your computer and use it in GitHub Desktop.
Disk Punch
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
| param ( | |
| $DriveToPunch = 'C', | |
| $PathToBlackHoleFile = 'DiskPunchBlackHole.file', | |
| $FreeSpaceToLeave = 5MB | |
| ) | |
| $bytesToPunchOutOfTheDrive = (Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='${DriveToPunch}:'").FreeSpace - $FreeSpaceToLeave | |
| $blackHoleFile = [IO.File]::Create("${DriveToPunch}:\$PathToBlackHoleFile") | |
| $blackHoleFile.SetLength($bytesToPunchOutOfTheDrive) | |
| $blackHoleFile.Close() | |
| Write-Host "We just punched a $bytesToPunchOutOfTheDrive bytes large hole in the $DriveToPunch drive. This leaves the drive with a pitiful $FreeSpaceToLeave bytes worth of space." | |
| Write-Host "To regain the storage space, delete the file at ${DriveToPunch}:\$PathToBlackHoleFile." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment