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!

About Boe Prox

Microsoft Cloud and Datacenter MVP working as a SQL DBA.
This entry was posted in powershell and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s