I’m a huge fan of the command line. There’s nothing you cannot do from the command line in Linux; in Windows, things were a lot harder. For too long Microsoft focused on GUI and neglected the command line. (This is still noticeable where the terminal window on windows is concerned, which is still decades behind Linux. I’ve used Console2 for ages, but I just discovered Scott Henselman’s blog and he suggested ConEmu and I’m giving that try now. Looks very good.)
- Ensure all my computers use the same profile
- Ensure all my computers have access to the same modules
- Allow computer specific settings to be set easily
Next was getting my modules to load. I started by trying to look at way to manipulate the path or to automatically copy the modules to the Powershell folder. This was ridiculously convoluted and there had to be an easier way. It took some searching, but I eventually came across $env:PSModulePath. Yep, the search path for modules.
I therefore mapped a drive to my modules directory and updated the modules path:
My modules all now load without any problems. Note that powershell: is a mapped drive as well.PowerTab was causing some issues, but I fixed those by moving the settings file into the AppData folder; which can be set in the first run wizard. Best solution in any case as different computers will have different things installed, and might need different settings.
That’s all working. The final thing is custom settings per computer. This was actually the easiest, especially once I’d figured out everything for the other two of my requirements and I was able to simply write it:
This looks for a file called profile_<computer>.ps1 and dot-sources it. Simple.
You may wonder about some of my strange variable naming. I tend to like things neat, and I create a whole load of variables during my profile initialisation. I therefore have a naming convention for variables I don’t need once the scripts have finished running, as a side effect of dot-sourcing a script is that the variables don’t drop out of scope.
At the end of my profile therefore I have:
and all my script variables are gone and I’m left with a very neat Powershell session that works the way I want it to, on any computer.