header image

Tidying up the favourites list

Posted by: | June 26, 2011 | No Comment |

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


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{             
$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"             
Lists defined favourites

Lists favourites defined in Internet Explorer


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

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.

under: PowerShellV2