Save your PowerShell Profile in your dotfiles repo

Koen Verburg
2 min readJul 21, 2020

--

Photo by Luca Bravo on Unsplash

This is a follow up article on Setting up powershell for development.

So you have a Profile setup for Powershell that’s great, it a good practice to save this Profile in a repository so your setup saved up in the cloud.

A popular place to store and manage your configurations is in a dotfiles directory. The name dotfiles come from the fact that most configurations are saved in a file that starts with a . If you look at .bashrc or a .vimrc you can see a pattern.

Let’s get started

Open up an Administrator PowerShell window and let’s make a directory and cd into it and initials git.

mkdir ~\dotfiles
cd ~\dotfiles\
git init

Your PowerShell Profile is stored in the path below.

~\Documents\PowerShell

Let’s move this file to our new dotfiles folder using the following command.

mv ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 ~\dotfiles\Microsoft.PowerShell_profile.ps1

Now that we have moved the profile, PowerShell can’t see it. Because we moved it out of the known path where Powershell looks for it. We are going to symlink this from the dotfiles to the location where PowerShell looks for it.

Create a file in your dotfiles folder and name it like symlink.ps1, open it up in VSCode and Paste in the following code.

New-Item -Path ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 -ItemType SymbolicLink -Value (Get-Item ".\Microsoft.PowerShell_profile.ps1").FullName

This line above will create a new item with the type of a symbolic link, every neat if you ask me. Now run the symlink.ps1 file like so.

.\symlinks.ps1

And reload the profile using.

. $Profile

If everything went correctly, nothing should change.

Alright, the last step is to create a dotfiles repo on GitHub or any other repository hosting platform like Gitlab or Bitbucket. Commit your changes and push it up!

That’s it! Now you have your PowerShell Profile in a git repository so it’s saved up in the cloud.

Want some inspirations for your dotfiles? Have a look at mine.

--

--

Koen Verburg

Software Engineer based in Rotterdam — Photographer, Art Enthusiast, Dreamer, and thinker.