特定PowerShell模块未自动加载

时间:2015-12-22 16:49:09

标签: powershell iis iis-7.5 powershell-v4.0 web-administration

我在Windows Server 2012 R2上使用PowerShell 4。

在调用来自此模块的Cmdlet时,特定模块WebAdministration不会自动加载。我试过的所有其他模块成功自动加载。我可以使用Import-Module手动加载此模块,它的行为符合预期。

  • PSModulePath环境变量包含模块的路径。此路径中的其他模块自动加载。
  • 该模块不是自定义的。它是一个内置的IIS功能。该功能已启用。
  • 启用自动加载。 $ PSModuleAutoLoadingPreference设置为“All”
  • Get-Command“Get-WebBinding”不起作用,但是Get-Command |其中{$ _。Name -eq“Get-WebBinding”}的确如此。
  • Get-Module -ListAvailable |其中{$ _。Name -eq“WebAdministration”}返回具有正确路径的模块。

PSModulePath =%SystemRoot%\ system32 \ WindowsPowerShell \ v1.0 \ Modules \ 网络管理模块路径 = C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ Modules \ WebAdministration



简单测试的输出

PS C:\ Users \ Administrator> $ PSModuleAutoLoadingPreference =“全部”

PS C:\ Users \ Administrator>得到-WebBinding Get-WebBinding:术语“Get-WebBinding”不被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查拼写 如果包含名称,或者包含路径,请验证路径是否正确,然后重试。 在行:1个字符:1 + Get-WebBinding + ~~~~~~~~~~~~~~     + CategoryInfo:ObjectNotFound:(Get-WebBinding:String)[],CommandNotFoundException     + FullyQualifiedErrorId:CommandNotFoundException

PS C:\ Users \ Administrator>导入模块Web管理

PS C:\ Users \ Administrator>得到-WebBinding

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



任何有关自动加载不起作用的建议都将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:0)

尝试重新安装模块以查看是否有作用。

如果这行不通,但令人烦恼的是自动加载功能无法正常运行,则可以在使用模块之前导入该模块,并期望它能够正常工作。

Import-Module WebAdministration
Get-WebBinding

或者如果您需要单线:

Import-Module WebAdministration; Get-WebBinding