Skip to content

Instantly share code, notes, and snippets.

@canoas
Created February 13, 2014 14:45
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 canoas/8976244 to your computer and use it in GitHub Desktop.
Save canoas/8976244 to your computer and use it in GitHub Desktop.
Powershell Script to clear an Url from TMG/ISA Cache
param(
$url = (Read-Host "Url? e.g http://www.maxfinance.pt/img/frame5.jpg")
)
begin {
$tmgroot = new-object -comobject FPC.Root
$tmgarray = $tmgroot.GetContainingArray()
$myCache = $tmgArray.Cache.CacheContents
$regex = ‘([a-zA-Z]{3,})://([\w-\.]+)(/[\w- ./?%&=]*)*?’
}
process {
if($url -match $regex) {
$hostname = $Matches[2]
$ip =[System.Net.Dns]::GetHostAddresses($hostname) | select -ExpandProperty IPAddressToString
$cachedUrl = $url.Replace($Matches[0], "zttp://$ip/$hostname")
try {
$myCache.FetchUrl("", $cachedUrl ,0,0) # "","zttp://83.240.174.194/www.maxfinance.pt/img/frame7.jpg",customTTL,fpcTtlIfNon
Write-host -ForegroundColor green "Done clearing $cachedUrl"
}
catch {
if($_.Exception.Message.Contains("The system cannot find the file specified")) {
Write-Warning "Cache Hit not found!"
}
else
{
throw
}
}
}
else
{
write-warning "Error parsing url"
$Matches
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment