If you commonly work with multiple PowerShell modules on different computers, this article is for you.

You’re going to learn one way to use a cloud file storage service to keep your PowerShell modules with you wherever you go.

The Problem

These days, many of us work on different computers for work. Some of those computers may be on the work network, some across a VPN connection, and some completely disconnected from work. When you’re a PowerShell guy/gal, you’re constantly downloading new copies of your modules.

I, personally, have dozens of various Powershell modules that I use on a daily basis. I’ve always found it to be a challenge to ensure a consistent PowerShell environment across all of my computers until I had an epiphany one day. Modules are just text files placed in a specific location on your computer. Why not use Dropbox?

Using DropBox, or any cloud storage provider that syncs files, would allow me to keep all of these files in sync and not have to worry about re-downloading them all of the time.

One problem though. DropBox, and other services, require all files to be in a specific folder. Unless you’re using a cloud storage provider to just sync PowerShell modules, you need to map a folder in the $env:PSModulePath array to DropBox.

If only you could create a couple of subfolders in your main Dropbox folder and just link to those folders in all my computers. Fortunately, you can, with symbolic links.

Windows Symbolic Links

Symbolic links are a great way to create “shortcuts” to folders, much like you have LNK files that create shortcuts on your desktop. Symbolic links can make Windows think that your PowerShell modules folder that exists in C:\Dropbox\PowerShellModules is actually at C:\Program Files\WindowsPowerShell\Modules, for example.

You could also put your profile in DropBox too, by creating a C:\DropBox\ProfileFolder folder while it’s actually in C:\Users\abertram\Documents\WindowsPowerShell.

Making Modules Available Everywhere

To solve the problem of PowerShell modules not being ubiquitously available everywhere, let’s set up Dropbox on each computer and create some symbolic links.

Learn how to automate IT tasks in PowerShell. Download this eBook

Install DropBox – To get started, you’ll first need to sign up for a DropBox account. Once you have an account, you’ll need to install DropBox on each computer that you’ll need your PowerShell modules to show up on.

Find the module folder – Once you’ve got Dropbox installed, you’ll then need to find where the modules reside on the filesystem. To find those paths, take a look at the folder paths in $env:PSModulePath. For this demo, all examples will be using the system-wide path at C:Files. This folder will be the “linked” folder that will link to a subfolder in the main Dropbox folder.

Move all PowerShell modules to the Dropbox folder – Close all PowerShell sessions and move the entire C:Filesfolder to [DropboxFolderPath]. Be sure to move the entire folder.

mkdir C:\DropBox\PowerShellModules

Move-Item -Path C:\Program Files\WindowsPowerShell\Modules -Destination C:\DropBox\PowerShellModules

Create the symbolic link – Next, you need to “link” the two folders together with a symbolic link. Symbolic links can be created using the mklink* utilitymklink* allows you to specify two folder paths – the linked path and the real path. In this example, I now have all modules in the C:\Dropbox\PowerShellModules folder but I want PowerShell to think they’re in the C:\Program Files\WindowsPowerShell\Modules.

To create the symbolic link with mklink, open up a command prompt and run the following command:

mklink /d "C:\Program Files\WindowsPowerShell\Modules" "C:\Dropbox\PowerShellModules"

When the link is created, you’ll then see a *Modules* folder shortcut where your old *Modules* folder used to be.

Ensure PowerShell still sees your modules – To confirm PowerShell can still use the modules, open up a PowerShell console and try to import one. Everything should still work as expected.

At this point, you can begin working with modules exactly as you did before. The only difference now is that you’ll be working from that new Dropbox folder location and getting all changes synced to the cloud!

Conclusion

There are many ways to keep your local PowerShell modules backed up to the cloud – using Dropbox is only one example. This article was meant to inspire some new ideas and to show you that even though you work locally with modules doesn’t mean you can’t leverage the power of the cloud to use those modules wherever you work.

Topics: IT insightsPowerShellCloud Computing

Source:https://blog.ipswitch.com/how-to-bring-your-powershell-modules-to-the-cloud