Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.