Created
January 14, 2015 22:15
-
-
Save mkropat/8eaf13fb3dc76f4b7626 to your computer and use it in GitHub Desktop.
Delete all files in 'Temporary ASP.NET Files' at boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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