$sleepDuration = 5
write-host "Restarting IIS and sleeping $sleep seconds!"
Stop-Service W3SVC,WAS -force
Start-Sleep -s $sleepDuration
write-host "Deleting Temporary Internet Files!"
$dirName = "Temporary ASP.NET Files";
$directories = @(gci "c:\windows\Microsoft.Net" -r -force -i $dirName)
foreach($x in $directories){
$childDirectories = @(gci $x)
foreach($y in $childDirectories){
remove-item "$x\$y" -r -force;
}
}
Start-Service W3SVC,WAS
2 comments:
I can't take full credit for it but this script helped me so I thought I'd share it.
https://www.kittell.net/code/powershell-clear-temporary-asp-net-files/
You wrote:
Restarting IIS and sleeping $sleep seconds!
and it should be
Restarting IIS and sleeping $sleepDuration seconds!
otherwise your script shows a space where the sleep duration is
--
The original script has a 10-second wait plus you can just use
Remove-ChildItem YourDirectory -Recurse -Force -ErrorAction SilentlyContinue
Post a Comment