PowerTip: Turn Off PowerShell Module Autoload

PowerTip: Turn Off PowerShell Module Autoload

  • Comments 1
  • Likes

Summary: Learn how to turn off Windows PowerShell module auto-loading.

Hey, Scripting Guy! Question I want to disable the Windows PowerShell 3.0 module automatic loading of modules. How do I do this?

Hey, Scripting Guy! Answer Set the value of the $PSModuleAutoloadingPreference automatic variable to none, as shown here.

$PSModuleAutoloadingPreference = "none"

Note   I do not recommend you make this change except in very specific situations and for very specific reasons. The number of Windows PowerShell cmdlets and functions in Windows Server 2012 and Windows 8 would make knowing which module a particular command resided in extremely difficult; with this change in place, you have to specifically load the module prior to using any commands.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • SG; Love your blog! I've been following for a long time and no matter how my skill progresses I still find relevant material here! Here's something I hope can add value to your post. It's real handy to have modules automatically load, like when I'm looking around for a cmdlet. I just start typing get-somenoun and hit tab until it shows me something close, it's great! But I have tons and tons of modules on my management workstation where I do more administrating and less hunting and pecking (that is, by time I'm on my management machine I usually already know what I want to do). When auto loading is enabled it really slows down tab completion. Sometimes it even hunts for a module when I'm running custom functions, slowing them down, also. So I wrote this function to make it easy to configure (that is, I don't have to come to your page because I can never remember the variable name $PSModuleAutoloadingPreference, and I already have plenty of reasons to come visit your blog). I put this in my PS profile and now changing the setting is as easy as typing set-au :) Anyway, here's the code! I put the other possibilities in a ValidateSet so the Mode param will tab complete, too. I hope someone else finds it useful! # set autoloading modules function set-automod { param([ValidateSet( "All","None","ModuleQualified" )] $mode = "None") # All, None, ModuleQualified: mymodule\cmdletname $PSModuleAutoloadingPreference = $mode $outObj = new-object psobject -property @{ PSModuleAutoloadingPreference = $PSModuleAutoloadingPreference } $outObj } function get-automod { # All, None, ModuleQualified: mymodule\cmdletname $outObj = new-object psobject -property @{ PSModuleAutoloadingPreference = $PSModuleAutoloadingPreference } $outObj } Here's what the output looks like: PS C:\> get-automod PSModuleAutoloadingPreference ----------------------------- none PS C:\> set-automod -mode ModuleQualified PSModuleAutoloadingPreference ----------------------------- ModuleQualified