【发布时间】:2016-03-29 00:06:18
【问题描述】:
我在 Windows Server 2012 R2 上使用 PowerShell 4。
调用来自该模块的 Cmdlet 时,特定模块 WebAdministration 不会自动加载。我尝试成功自动加载的所有其他模块。我可以使用 Import-Module 手动加载这个模块,它的行为符合预期。
- PSModulePath 环境变量包含模块的路径。此路径中的其他模块会自动加载。
- 该模块不是自定义的。它是一个内置的 IIS 功能。该功能已启用。
- 自动加载已启用。 $PSModuleAutoLoadingPreference 设置为“全部”
- Get-Command "Get-WebBinding" 不起作用,但 Get-Command | {$_.Name -eq "Get-WebBinding"} 在哪里。
- 获取模块-ListAvailable |其中 { $_.Name -eq "WebAdministration"} 返回具有正确路径的模块。
PSModulePath = %SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\ WebAdministration 模块路径 = C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration
简单测试的输出
PS C:\Users\Administrator> $PSModuleAutoLoadingPreference = "All"
PS C:\Users\Administrator> Get-WebBinding Get-WebBinding:术语“Get-WebBinding”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查拼写 的名称,或者如果包含路径,请验证路径是否正确,然后重试。 在行:1 字符:1 + 获取 WebBinding + ~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Get-WebBinding:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\Administrator> Import-Module WebAdministration
PS C:\Users\Administrator> Get-WebBinding
协议绑定信息 sslFlags -------- ------ -------- http *:8082:0 http *:8081: 0
任何关于为什么自动加载不起作用的建议将不胜感激。谢谢!
【问题讨论】:
-
您是否尝试将其添加到您的 PowerShell 配置文件中,以便在当前会话之外继续导入?
-
我可以采用这种解决方法,但我对根本原因更感兴趣。自动加载功能应该适用于这个模块,但它不适用于我的环境。
-
不知道。如果没有您的特定路径、变量或环境信息,很难诊断。您可以通过原始帖子中的一行代码来解决您的问题。
-
@kareed44 虽然我同意这很烦人并且找到根本原因是有意义的,但我认为您不应该依赖模块自动加载而只是为了方便。
-
尝试从
%LocalAppData%\Microsoft\Windows\PowerShell\CommandAnalysis中删除所有内容并开始新的 PowerShell 会话。
标签: powershell iis iis-7.5 powershell-4.0 web-administration