Created
June 21, 2016 11:27
-
-
Save erichexter/e77bdbfd8d593ffb0c9ebd503e069151 to your computer and use it in GitHub Desktop.
Free disk space on Windows dev server
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
| | |
| $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