PowerShell v3: Autoloading Modules

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.

Discuss this Blog Entry 1

on Oct 10, 2011
Start getting tired of Microsoft releasing on version after another of its products, as soon you start learning one version you find it too late, because a newer version is already out. I have just bought a couple of books dealing with PowerShell v.2 now MS is releasing PowerShell v.3, The same story with Windows OS.

Please or Register to post comments.

What's PowerShell with a Purpose Blog?

Don Jones demystifies Windows PowerShell.

Blog Archive

Sponsored Introduction Continue on to (or wait seconds) ×