Synchronize your PowerShell Profile with OneDrive

by Bharat Suneja

I make frequent changes to my PowerShell profile and like to have the same PowerShell envirnoment on all computers that I use PS from. To accomplish this, I used to copy the PowerShell profile to a folder on OneDrive (previously known as SkyDrive) and copy it back to the WindowsPowerShell folder on other computers – first, manually, and then using a script.

But there’s an easier way to have a single copy of your PowerShell profile and store it on OneDrive. This method allows PowerShell to automatically use the synchronized version on OneDrive. If you make changes to the profile, you no longer have to worry about copying the updated local version to OneDrive (manually) or sync/copy the updated version from OneDrive to all computers.

If you’re thinking about how complicated this solution is going to be, you can discard that thought right now! If simple solutions make you happy, this should make you jump with joy.

The caveat with this approach, if it can be called that: changes AND deletions to your PowerShell profile file are synced to all computers where you set it up.

Folder or file Default path
Windows user profile C:\Users\<username>
PowerShell profile file C:\Users\<username>\Documents\WindowsPowerShell\
Microsoft OneDrive folder C:\Users\<username>\OneDrive

Here’s how it works:

  1. Install OneDrive The OneDrive app is included in Widows 8 and later. If you don’t have the app installed on your computer, download and install it.
  2. Create a WindowsPowerShell folder on OneDrive Navigate to your OneDrive folder (the cached copy on your local drive) and create a WindowsPowerShell folder here.

    By default, the OneDrive app synchronizes your data to the OneDrive folder in your user profile (Default: C:\users\<username>\OneDrive). I change mine to a root level folder (for example: C:\Bharat\OneDrive) to make it easier to type.

  3. Rename the WindowsPowerShell folder in your user profile Check the Documents folder in your profile (typically C:\users\<username>\Documents). If you have a WindowsPowerShell folder, rename it to something like WindowsPowerShell-BAK.
  4. Create a symbolic link Create a symbolic link called WindowsPowerShell in the Documents folder and point it to the WindowsPowerShell folder in your OneDrive folder. Do this using a command prompt (cmd). PowerShell doesn’t recognize the mklink command.
    1. Navigate to the Documents folder in your user profile.
    2. Create the symbolic link.

      mklink /D WindowsPowerShell c:\Bharat\OneDrive\WindowsPowerShell

  5. Rinse and repeat on your other computers.

    Tip: Before you create the symbolic link to the WindowsPowerShell folder on other computers, the folder should be synchronized from OneDrive to that computer. Make the WindowsPowerShell folder in your OneDrive available offline. Use Windows Explorer to browse to your local OneDrive folder > right-click the WindowsPowerShell folder and select Make available offline.

Now start PowerShell. If you have a PowerShell profile in the OneDrive folder, it’ll load by default. Any changes made to the profile will sync to the other computers.

{ 0 comments… add one now }

Leave a Comment

{ 1 trackback }

Previous post:

Next post: