Skip to content

Instantly share code, notes, and snippets.

@mkropat
Created January 14, 2015 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkropat/8eaf13fb3dc76f4b7626 to your computer and use it in GitHub Desktop.
Save mkropat/8eaf13fb3dc76f4b7626 to your computer and use it in GitHub Desktop.
Delete all files in 'Temporary ASP.NET Files' at boot
# delete-temp-aspnet.ps1
#
# Delete all files in 'Temporary ASP.NET Files' at boot
param(
[switch] $Clean,
[switch] $Register
)
if ($Register) {
$scriptPath = $MyInvocation.MyCommand.Definition
Register-ScheduledJob -Name 'Clean Temporary ASP.NET Files' `
-FilePath $scriptPath -ArgumentList '-Clean' `
-Credential (Get-Credential) `
-MaxResultCount 30 `
-Trigger (New-JobTrigger -AtStartup -RandomDelay 00:00:30) | Out-Null
}
if ($Clean) {
$runtimePath = [System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()
$dotnetPath = Split-Path (Split-Path $runtimePath)
$frameworkPaths = @( 'Framework', 'Framework64' ) | foreach { Join-Path $dotnetPath $_ }
$versionDirs = Get-ChildItem -Path $frameworkPaths -Filter 'v*'
$tempAspnetDirs = $versionDirs | Get-ChildItem -Filter 'Temporary ASP.NET Files'
$tempAspnetDirs | Get-ChildItem | Remove-Item -Recurse -Force
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment