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!
%LocalAppData%\Microsoft\Windows\PowerShell\CommandAnalysis
and start new PowerShell session. – LamaGet-Module WebAdministration -ListAvailable
? DoesGet-Module WebAdministration -ListAvailable -Refresh
make any difference to the issue? If you import the module and do(Get-Module WebAdministration).ModuleBase
, is it in a versioned folder, and if so, if you copy the module contents to the folder above, does it fix the issue? (So you haveModules\WebAdministration\WebAdministration.psd1
, etc) – ClarettaclaretteWebAdministration
module autoloads for me when referencing a cmdlet inside of it for the first time. I'm not sure if PS 4.0 requiresFunctionsToExport
to be defined in the module'spsd1
file for autoloading to work with compiled module assemblies, but that is noticeably absent forWebAdministration
when checking today. I do not have a server with PS 4.0 to confirm the behavior on that version of PS. – LeavenworthWebAdministration
provides theIIS:
PSDrive. However, as indicated in my previous comment, I am able to autoload theWebAdministration
module on WS 2016 with PS 5.1 installed, which goes against this statement. My hypothesis is this limitation might not be relevant in PS 5.1+, but I can't say for certain since I don't have a PS 4.0 env to confirm. – Leavenworth