Darryl Mitchell

@darrmitchell

Lead Engineer @ NeoCloud working in cloud-based messaging and datacenter design/implementation

darrmit.me Guestbook

PowerShell Profile Syncing

I switch devices a lot - laptops, desktops, management VMs, etc. - and generally whatever device I'm on I'm using PowerShell extensively.

I predominantly used Mac/Linux from 2006-2017 and got used to certain tools - openssl, dig, whois, etc. - that I need in a shell, and Windows doesn't have those tools (even if it has some native "equivalents", like Resolve-DnsName). Ironically, I made the switch back to Windows specifically because at the time my most used PowerShell module, MsOnline, wasn't showing any signs of making the jump to MacOS. But then they switched to AzureAD. I digress..

It's easy enough to download these tools and create aliases in a PowerShell profile for them, but it makes switching between devices a pain. The solution I came up with is to store my PowerShell profile, downloaded utilities, and scripts in OneDrive (or Google Drive or Dropbox) and just point to that with a symlink on each machine.

By default, PowerShell stores its profile in the user's Documents folder in a folder called "WindowsPowerShell". To begin, backup that file (assuming you're already in ~/Documents/WindowsPowerShell:

cp .\Microsoft.PowerShell_profile.ps1 .\Microsoft.PowerShell_profile.ps
1.old

Next, create a symlink in that location (~/Documents/WindowsPowerShell):

New-Item -Type SymbolicLink -Target 'C:\Users\Darryl\OneDrive\Utilities
\Microsoft.PowerShell_profile.ps1' -Name Microsoft.PowerShell_profile.ps1

Close and open PowerShell, and you should be able to use the profile that you symlinked to.

One issue I've found is different machines can have different usernames - for example "darryl" vs. "darryl.mitchell". This means that statically setting paths inside the PowerShell profile won't work. Thankfully, there's a PowerShell environment variable for that: $env:USERPROFILE

So, when you're specifying aliases with paths (I have dig, whois, openssl, and some other functions/scripts) make sure to use that variable so you avoid issues with differing profile names. Example:

Set-Alias dig "$env:USERPROFILE\OneDrive\Utilities\bind9\dig.exe"

You'll only receive email when Darryl Mitchell publishes a new post

More from Darryl Mitchell: