我在 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、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。在 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
协议绑定信息 sslFlags -------- ------ -------- http *:8082: 0 http *:8081: 0
任何关于为什么自动加载不起作用的建议将不胜感激。谢谢!