6

我在 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




任何关于为什么自动加载不起作用的建议将不胜感激。谢谢!

4

2 回答 2

0

以下是我每次启动 ISE 时选择加载模块的方式。这使我可以选择加载某些模块。我知道这不是您要求的,但这确实会自动加载模块,并且一定要注意这些模块是如何被调用的。

创建以下文件:

Path: C:\Users\<username>\Documents\WindowsPowershell
File: Microsoft.PowerShellISE_profileX.PS1

在文件中,我使用此代码,但根据需要进行修改:

$a = new-object -comobject wscript.shell
$intAnswer = $a.popup("Connect to Office 365?",0,"Office 365",4)
if ($intAnswer -eq 6){
    #YES - Go to Cloud     
    #$a.popup("You answered yes.")
    Set-Location H:\sandbox
    #.  .\Start3.ps1
    . .\Auto-Connector.ps1
    . .\Refresh-PSSession.ps1
    . .\ScriptLoaders.ps1
    . .\ESDSCRIPTS3.ps1

}else{
    Set-Location H:\sandbox
    Import-Module ActiveDirectory
}
于 2021-08-19T17:32:35.127 回答
0

尝试重新安装模块,看看是否有所不同。

如果这不起作用,虽然自动加载不起作用很烦人,但您可以在使用前导入模块并期望它工作。

Import-Module WebAdministration
Get-WebBinding

或者,如果您需要单线:

Import-Module WebAdministration; Get-WebBinding
于 2019-06-12T16:51:42.887 回答