Edit: At some point between publishing this post and now — 11:43 p.m. on Christmas Eve, Eve — I thought people consuming this post would benefit from seeing the menu open a CSV-based bookmark. A short gif has been added to the bottom of this post.
I do not know what my problem is, but for the last few years, I’ve been an anti-browser-bookmarks person. I don’t really have a good reason as to why, but I look forward to getting over it; I do. But until then, I have been saving all my links inside of a CSV file with the assumption that at some point I will write some PowerShell that will allow me to easily search my CSV file and then open links programmatically. Well, guess what, I finally wrote that.
The first thing sharing this project is going to require is a properly formatted CSV file we can both work from. No need to put mine in here; it would be full of links that are worthless to anyone but me. Copy and paste the comma-separated data below and save that off to a CSV file called Links.csv
Be sure to note the path where you chose to save it, as we will work with it as a part of this post.
Title,Link,Note PowerShell GitHub,https://github.com/PowerShell/PowerShell, PowerShell GitHub Issues,https://github.com/PowerShell/PowerShell/issues, PowerShell Docs GitHub,https://github.com/MicrosoftDocs/PowerShell-Docs, Powershell Docs GitHub Issues,https://github.com/MicrosoftDocs/PowerShell-Docs/issues, PowerShell Docs,https://docs.microsoft.com/en-us/powershell, PowerShell Gallery,https://www.powershellgallery.com, PowerShell Reddit,https://www.reddit.com/r/PowerShell, Twitter Legends @jeffhicks,https://twitter.com/JeffHicks, Twitter Legends @jsnover,https://twitter.com/jsnover, Twitter Legends @concentrateddon, https://twitter.com/concentrateddon, TechCrunch.com,https://techcrunch.com/,Tech News Cnet.com,https://www.cnet.com/,Tech News Gizmodo.com,https://gizmodo.com/,Tech News 9to5mac.com,https://9to5mac.com/,Tech News Engadget.com,https://www.engadget.com/,Tech News Wired.com,https://www.wired.com/,Tech News TechRadar.com,https://www.techradar.com/,News Axios.com,https://www.axios.com/,News
With our CSV in place, we can work through the below PowerShell and then take it for a test drive. Have a look and meet me below for a quick discussion, before we try it out.
function Find-Link { [CmdletBinding()] Param ( [Parameter()] $Path = 'C:\Users\tommymaynard\Documents\CSVs\Links.csv', [Parameter()]$Title,[Parameter()]$Link,[Parameter()]$Note ) #region Import CSV/filter. $AllLinks = Import-Csv -Path $Path $ FilterLinks = $AllLinks | Where-Object -FilterScript { $_.Title -like "*$Title*" -and $_.Link -like "*$Link*" -and $_.Note -like "*$Note*" } #endregion #region Create link menu. for ($i = 0; $i -lt $FilterLinks.Count; $i++) { "[$($i + 1)] $(($FilterLinks[$i]).Title)" } # for #endregion #region Prompt user. do { $Option = Read-Host -Prompt 'Link Number' } # do until ($Option -in (1..$FilterLinks.Count)) Start-Process -FilePath "$($FilterLinks[$($Option - 1)].Link)" #endregion }
The function is named Find-Link
, and it includes a -Path
parameter. This is the location of the CSV file. While the function contains a default path, it can be changed when the function is invoked by passing in a different value. The static entry in the function can also be permanently modified, as well — it is up to you.
Find-Link -Path '/users/landrews/Documents/bookmarks.csv'
When the file is imported, the entire CSV is assigned to the $AllLinks
variable. Then, it runs a command against that variable, creating a new variable, to filter down the results using the value(s) potentially passed to three other parameters: -Title
, -Link
, and -Note
. There is more than just the -Path
parameter. It does not check if any of these parameters were actually included, but it could have using $PSBoundParameters
. Once we have a filtered list of links to display, we cycle through them using a for
loop, which creates a menu of options. Here’s an example of one of the outputs created by invoking this command with the -Title
parameter.
Find-Link -Title Twitter [1] Twitter Legends @jeffhicks [2] Twitter Legends @jsnover [3] Twitter Legends @concentrateddon Link Number:
The final portion of the function is a do-until
loop. This invokes Read-Host
prompt until one of the available menu numbers is entered. When a number that is not included is entered, it will prompt the user again for a different value. Here is an example of that.
Find-Link -Title Twitter [1] Twitter Legends @jeffhicks [2] Twitter Legends @jsnover [3] Twitter Legends @concentrateddon Link Number: 8 Link Number: 15 Link Number: 4 Link Number:
When a value is selected that is included from the list, Start-Process
invokes the corresponding link. Before we close out, here are a few more examples.
Find-Link -Link powershell [1] PowerShell GitHub [2] PowerShell GitHub Issues [3] PowerShell Docs GitHub [4] Powershell Docs GitHub Issues [5] PowerShell Docs [6] PowerShell Gallery [7] PowerShell Reddit Link Number:
Find-Link -Note News [1] TechCrunch.com [2] Cnet.com [3] Gizmodo.com [4] 9to5mac.com [5] Engadget.com [6] Wired.com [7] TechRadar.com [8] Axios.com Link Number:
Find-Link -Note 'Tech News' [1] TechCrunch.com [2] Cnet.com [3] Gizmodo.com [4] 9to5mac.com [5] Engadget.com [6] Wired.com Link Number:
We can combine the parameters too, to further filter the results.
Find-Link -Title GitHub -Link powershell [1] PowerShell GitHub [2] PowerShell GitHub Issues [3] PowerShell Docs GitHub [4] Powershell Docs GitHub Issues Link Number:
There may be a few things to add over time, but for now, this gives me what I wanted. It is better than navigating to the document and copying out a link — never. again.