6
votes

Im using PowerShell 4 on Windows Server 2012 R2.

A specific module, WebAdministration, does not get auto loaded when calling a Cmdlet that comes from this module. All other modules I have tried auto load successfully. I can load this module manually using Import-Module and it behaves as expected.

  • The PSModulePath environment variable contains the path with the module. Other modules from this path auto load.
  • The module is not custom. It is a built in IIS feature. The feature is enabled.
  • AutoLoading is enabled. $PSModuleAutoLoadingPreference is set to "All"
  • Get-Command "Get-WebBinding" doesn't work, but Get-Command | where {$_.Name -eq "Get-WebBinding"} does.
  • Get-Module -ListAvailable | where { $_.Name -eq "WebAdministration"} returns the module with the correct path.

PSModulePath = %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\ WebAdministration Module Path = C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration



Output from simple test


PS C:\Users\Administrator> $PSModuleAutoLoadingPreference = "All"

PS C:\Users\Administrator> Get-WebBinding Get-WebBinding : The term 'Get-WebBinding' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + Get-WebBinding + ~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-WebBinding:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\Administrator> Import-Module WebAdministration

PS C:\Users\Administrator> Get-WebBinding

protocol bindingInformation sslFlags -------- ------------------ -------- http *:8082: 0 http *:8081: 0




Any suggestions on why the auto loading isn't working would be greatly appreciated. Thanks!

1
Have you tried adding it to your PowerShell profile so the import persists outside of your current session? - dfundako
I could resort to that workaround but I'm more interested in the root cause. The auto load functionality should work with this module but it doesn't in my environment. - kareed44
Don't know. Hard to diagnose without your specific paths, variables, or environment info. You have a solution to solve your problem with one line of code in your original post. - dfundako
@kareed44 while I agree that this is annoying and it makes sense to find a root cause, I don't think you should be relying on module auto-loading as anything but a convenience. - briantist
Try to remove everything from %LocalAppData%\Microsoft\Windows\PowerShell\CommandAnalysis and start new PowerShell session. - user4003407

1 Answers

0
votes

Try reinstalling the module to see if that makes a difference.

If that doesn't work, while it's annoying that the autoload isn't functioning, you can import the module before use and expect it to work.

Import-Module WebAdministration
Get-WebBinding

Or if you need a one-liner:

Import-Module WebAdministration; Get-WebBinding