Viewing Internet Explorer Favorites Using PowerShell

I wanted a quick way to look at all of my favorites and see what urls they are referencing. Of course, PowerShell comes to the rescue and I found a fairly easy way to accomplish this without having to dirty my hands with a COM object (using Shell.Application to hook into the Favorites folder).

Instead, I am using the [Environment] type accelerator to locate where the Favorites folder is at.

$IEFav = [Environment]::GetFolderPath('Favorites')
$IEFav

image

Now that I have this information, I can then begin to find all of the *.url files which are the Internet Explorer favorites. This is as simple as using Get-ChildItem to get all of the files; I can even get all of the folders in the favorites as well with no effort at all.

Get-ChildItem -Recurse $IEFav

image

Full Disclosure: I don’t really use Internet Explorer a lot. So these bookmarks were built on the fly for this article as well as a few more forthcoming articles.

Now that I know what and where all of my favorites are, lets take a look at one of the *.url files to see what it has in it.

Get-Content 'C:\Users\Administrator\Favorites\PowerShell\PowerShell Code Repository.url'

image

Quite a bit of information here, but all I really care about is the URL= line as this is the URL of the site that will pop open when you click on the favorite. I can pull this out of the file like so:

(Select-String -Path `
'C:\Users\Administrator\Favorites\PowerShell\PowerShell Code Repository.url' `
-Pattern "^URL").Line.Trim("URL=")

image

And there is the URL that I wanted! I can put this all together with a small amount of code:

Get-ChildItem ([Environment]::GetFolderPath('Favorites')) -File -Recurse | ForEach {
    [pscustomobject]@{
        Name = $_.Name
        URL = ($_ | Select-String "^URL").Line.Trim("URL=")
    }
}

image

Now you might be thinking that I have a great function or something lined up to make this even easier and you would be right! However, I am holding onto this for a little while longer and will show it at the end of this little series. Until then, I hope you enjoyed this article and I will follow up with an article on adding a new favorite for Internet Explorer.

This entry was posted in powershell and tagged , , . Bookmark the permalink.

4 Responses to Viewing Internet Explorer Favorites Using PowerShell

  1. Eric Kimminau says:

    My favorites has some REALLY long URL and your script chops off the URL as it captures it. Something has a character limit.

  2. mlebel says:

    I think your last two code snippets are missing some characters at the end if I compare with the print screen provided:
    -Pattern “^URL”).Line.Trim(“URL
    should be -Pattern “^URL”).Line.Trim(“URL=”)
    and -Pattern “^URL”).Line.Trim(“URL
    should be URL = ($_ | Select-String “^URL”).Line.Trim(“URL=”)}

  3. Pingback: Creating and Removing an Internet Explorer Favorite Using PowerShell | Learn Powershell | Achieve More

  4. Pingback: Creating and Removing an Internet Explorer Favorite Using PowerShell | Learn Powershell | Achieve More

Leave a comment