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
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!
Guti, I have the exact same qstn. DId u find an answer to yours?
This is an awesome article. Thank you so much. How would you modify this if lets say I had 3 different links that needed to be replaced part of some links within the favorites folder?
To give an example;
Search favorites folder and find anything that has:
http:// mysite.public.com/departmentname/public
http:// site.share.net/departmentname/public
http:// intra.public.com/departmentname/home
and change it to the following:
http://share.public.com/something/public
http://share.something.intra/something/public
http:// something.share.intra/something/home
Guti, I have the exact same qstn. DId u find an answer to yours?