Categories

Modifying favourites

if we use our get-favourite function to look at the content of favourite files

 

get-favourite | select -f 5 | foreach{""; get-content -Path $_.path}

 

we see this sort of structure

[DEFAULT]
BASEURL=http://www.bing.com/
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[InternetShortcut]
URL=http://www.bing.com/
IDList=
IconFile=http://www.bing.com/favicon.ico
IconIndex=1

 

Not all files have the BASEURL or [DEFAULT] section but they do have the [InternetShortcut]. The other bit we need to consider is the iconfile

We can put together a function to change the URL in a favourite

function set-favourite{             
[CmdletBinding()]             
param(            
[parameter(Mandatory=$true,            
   ValueFromPipeline=$true,             
   ValueFromPipelineByPropertyName=$true)]            
[ValidateNotNullOrEmpty()]            
[string]$path,            
            
[ValidateNotNullOrEmpty()]            
[string]$url            
)            
BEGIN{}#begin             
PROCESS{            
$lines = Get-Content -Path $path            
            
$i = 0            
foreach($line in $lines) {            
             
 if ($line.StartsWith("BASEURL") ){$lines[$i] = "BASEURL=$url"}            
 if ($line.StartsWith("URL") ){$lines[$i] = "URL=$url"}            
 if ($line.StartsWith("IconFile") ){$lines[$i] = "IconFile=$url/favicon.ico"}            
 $i++             
}            
            
Set-Content -Value $lines -Path $path            
            
}#process             
END{}#end            
            
<# 
.SYNOPSIS
Changes URL of a favourite

.DESCRIPTION
Changes URL of a favourite


.EXAMPLE
get-favourite | where {$_.Name -like "google"} | set-favourite -url "www.bing.com"

#>            
            
}


The function can be used as follows



get-favourite | where {$_.Name -like "google"} | set-favourite -url www.bing.com



 



Next job is to create a favourite from scratch

Leave a Reply