Obvious When You Know

Obvious When You Know

During the last 8 months of lockdown, a few things have helped keep my mental health in order. Two of these things are YouTube channels. The first of which is very much not work-related, but watching the people behind Cracking the Cryptic solve Sudoku puzzles seems to help me when I need to take a step away. One of their most known videos can be found here : The Miracle Sudoku. The sheer joy of solving the logic and finding the solution is someone infectious.

The other YouTube series has been a recent addition to Scott Hanselman’s channel. His welcoming and softly spoken explanations of computing terms are very enjoyable to watch. The information is clear and concise, for people in a similar boat to me (coming from Infrastructure) I can highly recommend his 3 video series on Git concepts. The other videos in the series can also contain the odd tip or new nugget of new information. This happened in his recent video about becoming overwhelmed. during this video he talks about reducing the mental load of repetitive tasks away from coding.

One of the tips Scott gives is using cloud storage for your tools and adding the folder location to your Windows Path. In the 15 years of working within various IT fields, I have regularly collated and curated groups of tools for use, sometimes even storing them in OneDrive/DropBox… The one thing I have never thought to do was add the folder directly onto the Windows Path. As they say, you learn something new every day, and somethings are just so obvious when you know!.

As part of this work to streamline my tools folder. I have uploaded it to OneDrive, which is a good starting point. But I thought it would be useful to have a small PowerShell script that does the Path modification for me. Not something I will be doing that often, but still good to have a quick script to run.

I started by looking at using the $ENV:PATH variables for modifying the Windows Path, this is great if you want it for a single PowerShell session, but it is not a persistent change. A quick google pointed to using the .Net libraries [System.Environment]::GetEnvironmentVariables('User').Path. So I just needed something that will quickly add the OneDrive\Tools\ folder to my User Path. Below is the full v1 script.

The script works for the base scenario I wanted, but using $ENV:OneDriveConsumer might be a better solution for the OneDrive path, as it allows for non-default installations.

Further Reading