PowerShell v3: Autoloading Modules

A neat (and potentially confusing) new feature in PowerShell v3 helps you load modules you didn't even know you needed to load.

Don Jones

October 10, 2011

1 Min Read
ITPro Today logo in a gray background | ITPro Today

This is about PowerShell v3, which is now available with the Windows 8 Developer Preview and as a standalone Community Technology Preview. As such, mycaveats about it apply.

I hate getting "command not found" errors in PowerShell. It's typically because I've opened a new PowerShell window, forgotten to load a module, and tried to run a command from that module. My bad, but annoying.

Windows 8 promises to make the problem worse. The Server version of the OS will ship with more than 80 modules. Am I supposed to just pop them all into a profile, so that PowerShell takes forever to start up? Or am I supposed to remember which cmdlet came from which module, and load them all manually?

As it turns out, neither. PowerShell v3 supports automatic cmdlet discovery and module loading. Essentially, it works like this: Commands like Get-Command will show not only loaded cmdlets, but also cmdlets that are accessible from any unloaded modules located in a folder that's part of the PSModulePath environment variable. That's important, because it means the shell's most important "discovery" mechanisms will be showing you what cmdlets are actually available - even if you haven't loaded them yet! Try to run one of those cmdlets, and PowerShell will automatically load the necessary module "just in time." Cool!

This behavior can be disabled, of course, through a built-in variable (check the VARIABLE: drive after installing v3 and you'll find it easily enough), but module autoloading promises to make cmdlets easier to run and easier to find.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like