Monthly Archive

Categories

Tidying up the favourites list

I recently showed how to generate a list of the favourites recorded on your system

http://msmvps.com/blogs/richardsiddaway/archive/2011/06/24/viewing-favourites.aspx

If like me you want to tidy these up from time to time it would be good not to have to search through all of them to perform the deletions using the GUI

Lets turn our previous script into an advanced function

function get-favourite{             
[CmdletBinding()]             
param()            
BEGIN{}#begin             
PROCESS{            
$favs = New-Object -ComObject Shell.Application            
Get-ChildItem -Path $favs.NameSpace(0x6).Self.Path -Recurse |            
where {-not $_.PSIsContainer} |            
foreach {            
 $fav = New-Object -TypeName PSObject -Property @{            
  Name = $_.BaseName            
  Path = $_.FullName            
 }            
             
 Get-Content -Path $_.FullName | foreach {            
  if ($_.StartsWith("URL=")) {            
   $fav | Add-Member -MemberType NoteProperty -Name URL -Value $_.Replace("URL=","")}            
 }            
 $fav.PSTypeNames[0] = "Favourite"             
 $fav            
}            
            
}#process             
END{}#end            
            
<# 
.SYNOPSIS
Lists defined favourites

.DESCRIPTION
Lists favourites defined in Internet Explorer


.EXAMPLE
get-favourite

.EXAMPLE
get-favourite | where {$_.Name -like "re*"}  

.EXAMPLE
get-favourite | where {$_.Name -like "ree*"} | Remove-Item   

#>            
            
}

A few simple changes give us the required code. I’ve added the full name of the favourite as a path property. This means I can pipe straight into remove-item as shown in the third example.

I’ve also reset the output object type because I want to create a format file for this so that the path isn’t displayed by default. I will add some functions to modify and create favourites as well.

Leave a Reply