简体   繁体   English

使用 Powershell 更新 IIS 的 SSL 绑定 7

[英]Updating SSL bindings for IIS with Powershell 7

I'm trying to update a PS5 script to PS7, mainly because the script does work that requires a PS Core module.我正在尝试将 PS5 脚本更新为 PS7,主要是因为该脚本确实需要 PS Core 模块才能工作。

Part of the script involved updating IIS bindings to use a different SSL Certificate.部分脚本涉及更新 IIS 绑定以使用不同的 SSL 证书。 The cert is in the store and ready to be used - I just need to change the thumbprint on the binding.证书在商店中并可以使用 - 我只需要更改绑定上的指纹。

My PS5 script used Get-WebConfiguration to get the bindings and then just looped through, calling RebindSslCertificate on relevant bindings.我的 PS5 脚本使用Get-WebConfiguration来获取绑定,然后循环通过,在相关绑定上调用RebindSslCertificate

I've tried using Set-WebConfigurationProperty and Set-WebBinding ;我试过使用Set-WebConfigurationPropertySet-WebBinding neither errors but neither actually updates the binding with IIS - example:既没有错误,但也没有真正更新与 IIS 的绑定 - 例如:

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

Could anyone help point me in the right direction for what I'm missing?谁能帮我指出我所缺少的正确方向?

Thanks, Mark.谢谢,马克。

PS, Apologies if this is a repeat question but all I can find is old stuff that doesn't work or relates to "-Set-Item IIS:\SslBindings" Maybe there is someway to get the IIS drive working with remoting? PS,抱歉,如果这是一个重复的问题,但我能找到的只是旧的东西不起作用或与“-Set-Item IIS:\SslBindings”有关也许有办法让 IIS 驱动器与远程处理一起工作?

Ran into this on 9/10/2021 using Powershell 7.1.4.使用 Powershell 7.1.4 于 2021 年 9 月 10 日遇到此问题。

As of date of writing, this is an open issue on github for PowerShell.在撰写本文时,这是 github 上针对 PowerShell 的未解决问题。

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

Issue is that PowerShell 7 is based on .NET Core and the PS module WebAdministrator is based on .NET Framework.问题是 PowerShell 7 基于 .NET 核心,PS 模块 WebAdministrator 基于 .NET 框架。

When you run当你跑

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.

Notice the mention of 'WinPSCompatSession' in the warning.请注意警告中提到的“WinPSCompatSession”。 If the module manifest doesn't indicate that the module is compatible with PowerShell Core, then it gets loaded via the Windows PowerShell Compatibility Feature.如果模块清单未表明该模块与 PowerShell 内核兼容,则它通过 Windows PowerShell 兼容性功能加载。

It seems this module partially works in compatibility mode, however if you try to work with IIS:\ then you start getting errors.似乎这个模块在兼容模式下部分工作,但是如果你尝试使用 IIS:\ 那么你就会开始出错。

Alternatively, if you run the parameter in the warning you get this.或者,如果您在警告中运行参数,则会得到此信息。

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'.

A quick test in PowerShell 7.1.4 will show you that you can't access the IIS connector. 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.

However, if you open up PowerShell 6 you can do this no problem.但是,如果你打开 PowerShell 6 你可以做到这一点没有问题。

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

Name
----
AppPools
Sites
SslBindings

My next step is trying to get this to work by loading the .NET assembly directly.我的下一步是尝试通过直接加载 .NET 程序集来使其工作。 Will update with the solution将更新解决方案

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM