Skip to content

Instantly share code, notes, and snippets.

@erichexter
Created June 21, 2016 11:27
Show Gist options
  • Save erichexter/e77bdbfd8d593ffb0c9ebd503e069151 to your computer and use it in GitHub Desktop.
Save erichexter/e77bdbfd8d593ffb0c9ebd503e069151 to your computer and use it in GitHub Desktop.
Free disk space on Windows dev server
$LowDisk = 0.20
$timestamp = get-date
$disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace
$freespace= $disk.FreeSpace / $disk.Size
if($freespace -lt $LowDisk ){
$folders = @(
'C:\Octopus\Files',
'C:\inetpub\logs',
'C:\Octopus\Applications\release',
'C:\Octopus\Applications\develop',
'C:\Octopus\Applications\develop1')
"$timestamp Low disk space on c: $freespace is less than $LowDisk"
foreach($folder in $folders){
gci $folder -Recurse -File | remove-item -force -ErrorAction Continue
}
}
else{
"$timestamp Nothing to do freespace is : $freespace is greater than limit of $LowDisk"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment