[英]Updating SSL bindings for IIS with Powershell 7
我正在尝试将 PS5 脚本更新为 PS7,主要是因为该脚本确实需要 PS Core 模块才能工作。
部分脚本涉及更新 IIS 绑定以使用不同的 SSL 证书。 证书在商店中并可以使用 - 我只需要更改绑定上的指纹。
我的 PS5 脚本使用Get-WebConfiguration来获取绑定,然后循环通过,在相关绑定上调用RebindSslCertificate 。
我试过使用Set-WebConfigurationProperty和Set-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 驱动器与远程处理一起工作?
使用 Powershell 7.1.4 于 2021 年 9 月 10 日遇到此问题。
在撰写本文时,这是 github 上针对 PowerShell 的未解决问题。
参考链接: https://github.com/PowerShell/PowerShellModuleCoverage/issues/14
问题是 PowerShell 7 基于 .NET 核心,PS 模块 WebAdministrator 基于 .NET 框架。
当你跑
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 内核兼容,则它通过 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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.