Remove all Cached folders from imagegen with powershell

by Damiaan Peeters 3. June 2015 22:08

UDPATE: read the comments for simple oneliners!

Sometimes you need to say goodbye to a good friend.  ImageGen served us very well.  But we made the switch to ImageProcessor some time ago.

The only thing, if you start to clean the media folder, are all the "Cached" folders.  To remove them we wrote a little powershell script to help us out.

$path = "C:\Projects\parentfoldertoclean"
cd $path

# delete Cached folders
get-childitem -Include Cached -Recurse -force | Remove-Item -Force –Recurse

# Delete any empty directories left behind after deleting the old files.
Get-ChildItem -Recurse -Force | Where-Object { $_.PSIsContainer -and (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }) -eq $null } | Remove-Item -Force -Recurse

Watch (tail) the umbraco Log file with powershell

by Damiaan Peeters 6. November 2013 19:02


Sometimes you want to watch the umbraco Log file.  You doubelclick the file in explorer time after time.  Scroll down and look what was added on the bottom.  If you ar lazier (smarter?), then you would open WebMatrix or Visual studio leave the file open and just click yes when it reloads.

If you are still looking for the log files: go to /app_Data/Logs/UmbracoTraceLog.txt

Watching while it moves?

if you ever used linux then you are probably already missing the TAIL command for ages.  We have a solution: powershell to the rescue!  Make sure you have installed powershell version 3.

Then create a new powershell file (eg. mylogviewer.ps1) in the root of the website. Paste in the code below: 

gc App_Data\Logs\UmbracoTraceLog.txt -Tail 10 -Wait

When you run this powershell command, you will see the that powershell stays active and will update the screen as soon as new lines arrive in your LogFile.  If you don't want to create the file yourself, i have added it compressed below. (170.00 bytes)

Download all nuget packages to your local server using powershell

by Damiaan Peeters 21. January 2013 09:02

Some time ago I found this script to download the nuget Packages to you local server.  Just for a reference I’ll put it the blog. They way I run this is using the Windows Powershell ISE.


I don’t remember where I got the link from.  But I do know when.  That was when nuget was out and I had no way of retrieving missing packages.  Since then, I run this script to our local NAS from time to time.

The Powershell Source

# --- settings ---
$feedUrlBase = ""
# the rest will be params when converting to funclet
$latest = $true
$overwrite = $false
$top = 1500 #use $top = $null to grab all or a number to get TOP 500 packages
# $destinationDirectory = join-path ([Environment]::GetFolderPath("MyDocuments")) "NuGetLocal"
$destinationDirectory = "L:\TEMP\NuGetLocal"

# --- locals ---
$webClient = New-Object System.Net.WebClient

# --- functions ---

# download entries on a page, recursively called for page continuations
function DownloadEntries {
param ([string]$feedUrl)
$feed = [xml]$webClient.DownloadString($feedUrl)
$entries = $feed.feed.entry
$progress = 0
foreach ($entry in $entries) {
    $url = $entry.content.src
    $fileName = $ + "." + $ + ".nupkg"
    $saveFileName = join-path $destinationDirectory $fileName
    $pagepercent = ((++$progress)/$entries.Length*100)
    if ((-not $overwrite) -and (Test-Path -path $saveFileName))
        write-progress -activity "$fileName already downloaded" `
                       -status "$pagepercent% of current page complete" `
                       -percentcomplete $pagepercent
    write-progress -activity "Downloading $fileName" `
                   -status "$pagepercent% of current page complete" `
                   -percentcomplete $pagepercent

    [int]$trials = 0
    do {
        try {
            $trials +=1
            $webClient.DownloadFile($url, $saveFileName)
        } catch [System.Net.WebException] {
            write-host "Problem downloading $url `tTrial $trials `
                       `n`tException: " $_.Exception.Message
    while ($trials -lt 3)

  $link = $ | where { $_.rel.startsWith("next") } | select href
  if ($link -ne $null) {
    # if using a paged url with a $skiptoken like
    # http:// ... /Packages?$skiptoken='EnyimMemcached-log4net','2.7'
    # remember that you need to escape the $ in powershell with `
    return $link.href
  return $null

# the NuGet feed uses a fwlink which redirects
# using this to follow the redirect
function GetPackageUrl {
param ([string]$feedUrlBase)
$resp = [xml]$webClient.DownloadString($feedUrlBase)
return $resp.service.GetAttribute("xml:base")

# --- do the actual work ---

# if dest dir doesn't exist, create it
if (!(Test-Path -path $destinationDirectory)) {
    New-Item $destinationDirectory -type directory

# set up feed URL
$serviceBase = GetPackageUrl($feedUrlBase)
$feedUrl = $serviceBase + "Packages"
if($latest) {
    $feedUrl = $feedUrl + "?`$filter=IsLatestVersion eq true"
    if($top -ne $null) {
        $feedUrl = $feedUrl + "&`$orderby=DownloadCount desc&`$top=$top"

while($feedUrl -ne $null) {
    $feedUrl = DownloadEntries $feedUrl

Certified Umbraco Master, Part of Umbraco Certified partner comm-it, .Net and Azure developer, seo lover. Magician in my spare time.

Month List