If your Temporary ASP.NET Files directory is getting out of hand there are a few things you can do about it.
First option I found was at https://sysadminspot.com/server-administration/powershell-cleanup-temp-asp-net-files/.
Get-ChildItem “C:\Windows\Microsoft.NET\Framework*\v*\Temporary ASP.NET Files” -Recurse | Remove-Item -Recurse
This option works well and in some cases could be the safer option as it can’t delete files that are currently in use.
I then found this option at https://foxsys.blogspot.com/2012/08/powershell-script-to-delete-temporary.html that in some ways is risker but is more thorough.
I like the second option when I can take a server out of a load balancer or temporary take the site down.
As a combination of both I came up with the below.
# WARNING ONLY RUN AFTER SERVER IS OUT OF LOAD BALANCER! # THIS SCRIPT WILL STOP/START SERVICES FOR YOUR WEBSITE $sleep = 10 clear $disk = ([wmi]"Win32_logicalDisk.DeviceID='c:'") "C: has {0:#.0} GB free of {1:#.0} GB Total" -f ($disk.FreeSpace / 1GB), ($disk.Size / 1GB) | write-output Write-Output "Stopping IIS and sleeping $sleep seconds!" Stop-Service W3SVC, WAS -force Start-Sleep -s $sleep Write-Output "Deleting Temporary Internet Files!" Get-ChildItem “C:\Windows\Microsoft.NET\Framework*\v*\Temporary ASP.NET Files” -Recurse | Remove-Item -Recurse #-Verbose Write-Output "Starting IIS Services" Start-Service W3SVC, WAS Get-Service W3SVC, WAS $disk = ([wmi]"Win32_logicalDisk.DeviceID='c:'") "C: has {0:#.0} GB free of {1:#.0} GB Total" -f ($disk.FreeSpace / 1GB), ($disk.Size / 1GB) | write-output