A PowerShell Module for Managing Internet Explorer Favorites

As promised, here is my module that I put together to make managing Internet Explorer favorites. The module is called IEFavorites and has 3 functions available:

  • Get-IEFavorite
  • Add-IEFavorite
  • Set-IEFavorite

There are also 4 aliases associated with this module:

  • gief (Get-IEFavorite)
  • aief (Add-IEFavorite)
  • sief (Set-IEFavorite)
  • rief (Remove-Item)

Simply import the module file and you are off and running!

Import-Module .\IEFavorites.psm1 -Verbose

image

Viewing the favorites can be done like this:

Get-IEFavorite

image

Adding a new Favorite is handled like so:

Add-IEFavorite -Name Twitter -Folder SocialNetwork `
-Url http://twitter.com -Verbose

image

If I want to remove a favorite, I just pipe my results of Get-IEFavorite into Remove-Item.

Get-IEFavorite -Name Drudge* -File | 
Remove-Item -Verbose

image

Lastly, editing a favorite is done using Set-IEFavorite:

Get-IEFavorite -Name Twitter* | 
Set-IEFavorite -NewName Facebook -NewUrl http://Facebook.com -Verbose

image

That is all to the module. Check it out and let me know what you think!

Download IEFavorites

http://gallery.technet.microsoft.com/scriptcenter/Internet-Explorer-f689cb89

Posted in Modules, powershell | Tagged , , , , | Leave a comment

Editing an Internet Explorer Favorite Using PowerShell

Closing out my little series on working with Internet Explorer favorites, I will show you how to edit an existing favorite using PowerShell.

We’ve already added a favorite, but what happens if I want to change the URL or the name of the favorite (or even both for that matter)? Well, we can use PowerShell with a little bit of parsing and make this happen in an easy amount of time.

I will be using the same technique as before to get the favorites path and then use that to locate a favorite which should be changed.

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

I am going to update the CNN favorite to change it to Drudge Report instead. But before I do that, I need to get that CNN favorite. This is a dramatic edit as I might as well delete CNN and just add the Drudge Report favorite, but this will show both editing the URL as well as the Name in one shot.

$Favorite = Get-ChildItem $IEFav -Recurse -Filter "*CNN*"

I also need to figure out what my new name and url will be.

$NewUrl = 'http://drudgereport.com'
$Newname = 'DrudgeReport'

Now I need to get the contents of the current favorite.

$lines = Get-Content $Favorite.FullName
$lines

image

Depending on the favorite (such as this one), there may be a lot of noise here that work through.  As long as you follow the steps below, the favorite will be modified and when used will take you to the new site specified.

I am now going to step through each line and if it starts with BASEURL=, URL= or IconFile=, I will replace the current URL with the new one.

$i=0
ForEach ($line in $lines) {
    If ($line.StartsWith("BASEURL")) {
        $lines[$i] = "BASEURL=$NewUrl"
    }
    If ($line.StartsWith("URL")) {
        $lines[$i] = "URL=$NewUrl"
    }            
    If ($line.StartsWith("IconFile")) {
        $lines[$i] = "IconFile=$NewUrl/favicon.ico"
    }            
    $i++  
}
Set-Content -Value $lines -Path $Favorite.FullName

Now that we have accomplished updating the URL on this favorite, it is time to rename the favorite so it matches the new URL.

Rename-Item -Path $Favorite.FullName -NewName "$NewName.url"

Perfect! The favorite has now been renamed and a matching URL was given to it. We can verify and test the favorite by doing the following:

Get-ChildItem $IEFav -Filter 'Drudge*' -Recurse | Invoke-Item

The next article will cover a module that I wrote to make managing your Internet Explorer favorites a little easier. Check it out!

Posted in powershell | Tagged , , | 3 Comments

Creating and Removing an Internet Explorer Favorite Using PowerShell

In a previous article, I showed you how you can view the Internet Explorer favorites as well as the URL for those favorites. Continuing on from that article, I will now walk through creating a new favorite for Internet Explorer using PowerShell.

Using the same approach as before, I need to get the folder path to the Favorites.

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

Because I am creating an Internet Shortcut, I need to create a COM object that will be used later on.

$Shell = New-Object -ComObject WScript.Shell

I am going to create a favorite of my site and place it in my already existing PowerShell folder. Because I am not using the root of Favorites, I need to add the PowerShell folder to my current $IEFav path.

$IEFav = Join-Path -Path $IEFav -ChildPath PowerShell

I need to figure out a name for the favorite, something that I want to show up when I click on the Favorites toolbar on Internet Explorer.

$Name = 'My Blog'

Next up is to build the fully qualified path to the favorite. I have to make sure that I add a .url so it is properly recognized as a favorite.

$FullPath = Join-Path -Path $IEFav -ChildPath "$($Name).url"

image

Now I just need the URL.

$url = 'http://learn-powershell.net'

Ok, while we have the file ready for creation, we still need to add the URL which will be referenced when clicked on. This is where our Shell.Application COM object comes into play.

$shortcut = $Shell.CreateShortcut($FullPath)
$shortcut.TargetPath = $Url
$shortcut.Save()

And just like that, the new Internet Explorer favorite has been created! We can quickly verify using the same techniques from the previous article and see the information is there.

image

I can even use Invoke-Item on this to bring up my site.

Invoke-Item $FullPath

Removing a favorite is very simply. Just use Get-ChildItem to get the file and use Remove-Item to delete it.

Get-ChildItem $IEFav -Recurse -Filter Bing* | 
Remove-Item -Verbose

image

That’s all there is to creating a favorite. Up next will be showing you how to edit an existing favorite. Stay tuned!

Posted in powershell | Tagged , , | Leave a comment

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.

Posted in powershell | Tagged , , | 4 Comments

I’m a Coach for the 2014 Winter Scripting Games

I was selected to help coach the Winter Scripting Games for 2014. What does this mean? Well, because the format for the Winter Games is a team format, I will be wandering around from team to team and looking at what they have been doing (if they allow me to look) and adding my two cents on how I think they are doing and the direction that they are going with their submission.

They can decide to a coaches advice, or ignore it. Either way, we will do what we can to help out each team and ensure that they give their best submission for the judges. Besides that, we will also be blogging what we are seeing (both good and bad) in hopes to also help the community out with working with PowerShell. I personally written my fair share of items from past Scripting Games that you can look at below:

https://learn-powershell.net/tag/scripting-games-2012-2/

https://learn-powershell.net/tag/scripting-games-2013-2/

http://blogs.technet.com/b/heyscriptingguy/archive/2012/03/30/tips-for-preparing-for-the-2012-powershell-scripting-games.aspx

Please use the following links below to get better prepared for this year’s Winter Scripting Games.

Announcements: http://powershell.org/wp/category/announcements/scripting-games/

Twitter Hashtag: #PshGames

Team Formation Tips: http://powershell.org/wp/2013/12/19/2014-winter-scripting-games-team-formation-tips/

Scripting Games Login Info: http://powershell.org/wp/2013/12/21/important-scripting-games-login-and-operational-information/

Have fun and good luck this year!

Posted in powershell, Winter Scripting Games 2014 | Tagged , , , | Leave a comment