Skip to content

Instantly share code, notes, and snippets.

@AndreasHassing
Created June 25, 2020 11:30
Show Gist options
  • Select an option

  • Save AndreasHassing/1760dfed9f39b33ec80bbedea88ff5a2 to your computer and use it in GitHub Desktop.

Select an option

Save AndreasHassing/1760dfed9f39b33ec80bbedea88ff5a2 to your computer and use it in GitHub Desktop.
Disk Punch
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