【问题标题】:Updating SSL bindings for IIS with Powershell 7使用 Powershell 7 更新 IIS 的 SSL 绑定
【发布时间】:2021-03-29 02:04:41
【问题描述】:

我正在尝试将 PS5 脚本更新到 PS7,主要是因为该脚本确实需要 PS Core 模块才能工作。

部分脚本涉及更新 IIS 绑定以使用不同的 SSL 证书。证书在商店中,可以使用 - 我只需要更改绑定上的指纹。

我的 PS5 脚本使用 Get-WebConfiguration 来获取绑定,然后循环执行,在相关绑定上调用 RebindSslCertificate

我尝试过使用 Set-WebConfigurationPropertySet-WebBinding;既没有错误,但也没有真正更新与 IIS 的绑定 - 示例:

Set-WebConfigurationProperty  -Name 'certificateHash'  -Value $newCert.Thumbprint -PSPath "IIS:\\"  ` 
-Filter "/system.applicationHost/sites/site/bindings/binding[@protocol='https'][@bindingInformation='*:443:hostname']"   `

谁能帮我指出我所缺少的正确方向?

谢谢, 标记。

PS,抱歉,如果这是一个重复的问题,但我只能找到不起作用或与 "-Set-Item IIS:\SslBindings" 相关的旧东西也许有办法让 IIS 驱动器与远程处理一起工作?

【问题讨论】:

  • 您使用的是哪个版本的 IIS?如果您使用的是 IIS 7,还需要安装 powershell 管理单元以支持 IIS 7powershell:iis.net/downloads/microsoft/powershell
  • 请先以管理员身份运行powershell。在尝试运行 powershell 脚本之前,请记住先导入 Web 管理:“Import-Module WebAdministration”。
  • 我正在使用 IIS 10 并且 Powershell 以管理员身份运行。我完全糊涂了。
  • 如果我使用其他命令会起作用吗?
  • 我找到了一篇关于PowerShell管理IIS网站绑定的博客,可以参考:4sysops.com/archives/manage-iis-website-bindings-in-powershell

标签: powershell ssl iis powershell-remoting


【解决方案1】:

使用 Powershell 7.1.4 于 2021 年 9 月 10 日遇到此问题。

截至撰写本文时,这是 GitHub 上针对 PowerShell 的一个未解决问题。

参考链接:https://github.com/PowerShell/PowerShellModuleCoverage/issues/14

问题是 PowerShell 7 基于 .NET Core 而 PS 模块 WebAdministrator 基于 .NET Framework。

当你跑步时

Import-Module WebAdministration
WARNING: Module WebAdministration is loaded in Windows PowerShell using WinPSCompatSession remoting session; please note that all input and output of commands from this module will be deserialized objects. If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.

请注意警告中提到的“WinPSCompatSession”。如果模块清单未表明该模块与 PowerShell Core 兼容,则会通过 Windows PowerShell 兼容性功能加载它。

该模块似乎在兼容模式下部分工作,但是如果您尝试使用 IIS:\,那么您开始收到错误。

或者,如果你在警告中运行参数,你会得到这个。

Import-Module -SkipEditionCheck WebAdministration
Import-Module: Could not load type 'System.Management.Automation.PSSnapIn' from assembly 'System.Management.Automation, Version=7.1.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

PowerShell 7.1.4 中的快速测试将显示您无法访问 IIS 连接器。

PS C:\Windows\System32> Import-Module WebAdministration
WARNING: Module WebAdministration is loaded in Windows PowerShell using WinPSCompatSession remoting session; please note that all input and output of commands from this module will be deserialized objects. If you want to load this module into PowerShell please use 'Import-Module -SkipEditionCheck' syntax.
PS C:\Windows\System32> cd IIS:\
Set-Location: Cannot find drive. A drive with the name 'IIS' does not exist.

但是,如果你打开 PowerShell 6,你可以做到这一点。

PS C:\WINDOWS\system32>  Import-Module WebAdministration
PS C:\WINDOWS\system32> cd IIS:\
PS IIS:\> dir

Name
----
AppPools
Sites
SslBindings

我的下一步是尝试通过直接加载 .NET 程序集来使其工作。将更新解决方案

[System.Reflection.Assembly]::LoadFrom("$env:systemroot\system32\inetsrv\Microsoft.Web.Administration.dll")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    • 2018-01-08
    • 1970-01-01
    • 2023-03-13
    • 2018-10-24
    • 1970-01-01
    • 2013-05-11
    相关资源
    最近更新 更多