Magic Commands – cleaning up ASP.NET temporary files

ASP.NET temporary files can quickly mount up and eat up disk space, especially if you deploy multiple times a day. This website provides a handy command that you can run to delete any unnecessary files:

Get-ChildItem "C:\Windows\Microsoft.NET\Framework*\v*\Temporary ASP.NET Files" -Recurse | Remove-Item -Recurse

You’ll get a few errors when it hits files in use, but apart from that it works a treat. You can run this as a scheduled task if you want to avoid having to do it manually all the time, or get your deployment tool to run it on every deployment to tidy up as you go (Octopus Deploy has its own library task to do something similar, for example).

How to time how long something takes to run in Windows

It can be useful to time how long certain commands take to run. With Powershell, you can do this easily using the Measure-Command cmdlet:

Measure-Command { ping | Out-Default }

Simply replace ping with whatever you want to time, and off you go. You’ll get a readout similar to this when your command finishes executing with details of how long it took:

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 3
Milliseconds      : 116
Ticks             : 31167663
TotalDays         : 3.60736840277778E-05
TotalHours        : 0.000865768416666667
TotalMinutes      : 0.051946105
TotalSeconds      : 3.1167663
TotalMilliseconds : 3116.7663

Disk Cleanup on Microsoft Windows Server

Servers run out of disk space too sometimes, but the Server versions of Windows don’t have the handy Disk Cleanup utility installed by default. If you want to get it back, you can run this Powershell command:

Install-WindowsFeature Desktop-Experience

or you can follow the instructions here if you’re more of a GUI person.

Both of these approaches install the “Desktop Experience”, which includes Disk Cleanup but also some other clutter that you may not want. For the purists out there who just want Disk Cleanup and nothing else, for Windows Server 2012 and earlier you can get the necessary files out of the WinSxS folder (check here for the relevant directories). However, as of Windows Server 2012 R2 this option is no longer available so you’ll have to just accept the added bloat of Desktop Experience.