Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PowerShell – Clear Temporary ASP.NET Files

Posted on October 13, 2019 By David Kittell

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
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PowerShell Windows Windows Server

Post navigation

Previous post
Next post

Related Posts

Column Name Search

Posted on February 25, 2013February 8, 2016

An extension of Table/View Column Information In the event that you need to find a table that has a specific column name. SELECT t.name AS table_name, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys.tables AS t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE ‘%requestNumber%’ ORDER BY…

Read More

Restrict Access to Internal IP

Posted on September 26, 2013October 26, 2015

Many times we have sites that are public but have pages that should only be viewed by internal users. Ideally the settings would be configured on the server level in IIS but if not possible for some reason this may help. One key thing to note is this code will…

Read More

Swift – iOS – GPS – Coordinates – Lat/Long to DMS

Posted on June 8, 2018

If you have a need for displaying the GPS location information in Degrees, minutes, and seconds (DMS) format these functions will help you out. func latlon2DMS(latitude: Double) -> String { var latitudeSeconds = latitude * 3600 let latitudeDegrees = latitudeSeconds / 3600 latitudeSeconds = latitudeSeconds.truncatingRemainder(dividingBy: 3600) let latitudeMinutes = latitudeSeconds…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • Front Page
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories
  • Raspberry Pi - Remove Default Apps
  • PowerShell - Change Windows CD/DVD Drive Letter
©2025 David Kittell | WordPress Theme by SuperbThemes