简体   繁体   English

New-WebBinding:无法检索 cmdlet 的动态参数

[英]New-WebBinding: Cannot retrieve the dynamic parameters for the cmdlet

We're using Windows 2012 Server R2.我们使用的是 Windows 2012 Server R2。

We're trying to automate the creation of LetsEncrypt certificates.我们正在尝试自动创建 LetsEncrypt 证书。 We're using LetsEncrypt-Win-Simple ( https://github.com/Lone-Coder/letsencrypt-win-simple ).我们正在使用 LetsEncrypt-Win-Simple ( https://github.com/Lone-Coder/letsencrypt-win-simple )。

Once the cert is created (via LetsEncrypt.exe) we have a .bat script that gets called (using the --script and --scriptparameters flags).创建证书(通过 LetsEncrypt.exe)后,我们将调用一个 .bat 脚本(使用 --script 和 --scriptparameters 标志)。 This runs powershell.exe and tries to create the necessary IIS binding.这将运行 powershell.exe 并尝试创建必要的 IIS 绑定。 The line in the .bat file is: .bat 文件中的行是:

powershell.exe -file c:\temp\SSLIISBinding.ps1 %1 %2 %3 %4

The %1-4 are args passed in by LetsEncrypt. %1-4 是 LetsEncrypt 传入的参数。 In the powershell script, the command we're trying to run is:在 powershell 脚本中,我们尝试运行的命令是:

$iis_host_name = $args[0]
$iis_site_name = $args[1]
$certificate_hash = $args[2]
$certificate_store = $args[3]

"IIS Host Name: " + $iis_host_name
"IIS Site Name: " + $iis_site_name
"Certificate Hash: " + $certificate_hash
"Certificate Store: " + $certificate_store

$guid = [guid]::NewGuid().ToString("B")
netsh http add sslcert hostnameport="${iis_host_name}:443" certhash=$certificate_hash certstorename=$certificate_store appid="$guid"
New-WebBinding -name $iis_site_name -Protocol https  -HostHeader $iis_host_name -Port 443 -SslFlags 1

The args are passed into the .bat fine, as we output them and they are showing correctly. args 被传递到 .bat 中,因为我们输出它们并且它们显示正确。

If we run the .bat file on its own, it works perfectly.如果我们自己运行 .bat 文件,它会完美运行。 If it gets called by LetsEncrypt.exe it fails, reporting the following issue:如果它被 LetsEncrypt.exe 调用,它会失败,报告以下问题:

New-WebBinding : Cannot retrieve the dynamic parameters for the cmdlet.
Retrieving the COM class factory for component with CLSID
{688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error:
80040154 Class not registered (Exception from HRESULT: 0x80040154
(REGDB_E_CLASSNOTREG)).
At C:\temp\SSLIISBinding.ps1:13 char:1
+ New-WebBinding -name $iis_site_name -Protocol https  -HostHeader
$iis_host_name  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : InvalidArgument: (:) [New-WebBinding], Parameter
   BindingException
    + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.IIs.Powe
   rShell.Provider.NewWebBindingCommand

I've googled, some mentioning something about 32bit vs 64bit powershell, but I've tried using all the different powershell.exe available.我用谷歌搜索过,有些人提到了 32 位和 64 位 powershell,但我已经尝试使用所有不同的 powershell.exe 可用。

Anyone hit this issue, or know to resolve.任何人都遇到过这个问题,或者知道如何解决。

If we call .bat directly from command line it works fine, just as part of being called via LetsEncrypt.exe.如果我们直接从命令行调用 .bat 它工作正常,就像通过 LetsEncrypt.exe 调用的一部分一样。 A permission problem?权限问题? Wrong powershell.exe?错误的powershell.exe?

That part of your question:你问题的那部分:

I've googled, some mentioning something about 32bit vs 64bit powershell我用谷歌搜索过,有些人提到了 32 位与 64 位 powershell

is already half of an answer.已经是答案的一半了。 Some commands do not run properly if bitness of PowerShell process does not match bitness of operation system.如果 PowerShell 进程的位数与操作系统的位数不匹配,某些命令将无法正常运行。 So, you need to run powershell.exe , which located in this %windir%\\System32\\WindowsPowerShell\\v1.0\\ directory.因此,您需要运行位于此%windir%\\System32\\WindowsPowerShell\\v1.0\\目录中的powershell.exe But there is a little problem described in this documentation topic :但是这个文档主题中描述了一个小问题:

In most cases, whenever a 32-bit application attempts to access %windir%\\System32, the access is redirected to %windir%\\SysWOW64.在大多数情况下,每当 32 位应用程序尝试访问 %windir%\\System32 时,访问都会重定向到 %windir%\\SysWOW64。

Thus, if 32-bit program on 64-bit OS invoke %windir%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe , it will actually invoke 32-bit version of PowerShell from here %windir%\\SysWOW64\\WindowsPowerShell\\v1.0\\ instead of 64-bit one.因此,如果 64 位操作系统上的 32 位程序调用%windir%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe ,它实际上会从这里调用 32 位版本的 PowerShell %windir%\\SysWOW64\\WindowsPowerShell\\v1.0\\而不是 64 位。 To actually invoke 64-bit PowerShell from 32-bit application you need to use this trick:要从 32 位应用程序实际调用 64 位 PowerShell,您需要使用以下技巧:

32-bit applications can access the native system directory by substituting %windir%\\Sysnative for %windir%\\System32. 32 位应用程序可以通过将 %windir%\\Sysnative 替换为 %windir%\\System32 来访问本机系统目录。 WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access. WOW64 将 Sysnative 识别为特殊别名,用于指示文件系统不应重定向访问。

I've got the same error when running the following cmdlet:运行以下 cmdlet 时,我遇到了同样的错误:

PS> Remove-WebAppPool -Name 'Test'

Remove-WebAppPool : Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for
component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not
registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
At line:1 char:1
+ Remove-WebAppPool -Name 'Test'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Remove-WebAppPool], ParameterBindingException
    + FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.IIs.PowerShell.Provider.RemoveAppPoolCommand

The reason was because I ran it using Windows PowerShell (x86) on my Windows 10 x64 machine.原因是我在 Windows 10 x64 机器上使用 Windows PowerShell (x86) 运行它。

When I tried the same but using Windows PowerShell, which is 64 bit version, it worked just fine.当我尝试相同但使用 64 位版本的 Windows PowerShell 时,它工作得很好。

I think your $guid is the issue.我认为你的 $guid 是问题所在。 The GUID needs to be the GUID of the program to bind the cert to. GUID 必须是要将证书绑定到的程序的 GUID。 For your example port 443 is only bound to a random GUID, and not your program's GUID.对于您的示例,端口 443 仅绑定到随机 GUID,而不绑定到您程序的 GUID。 IIS and other apps have a static GUID that you will want to use. IIS 和其他应用程序具有您想要使用的静态 GUID。 If the GUID for a powershell script then Get-host is the powershell host executing code so that's the GUID you need.如果是 powershell 脚本的 GUID,则 Get-host 是执行代码的 powershell 主机,因此这就是您需要的 GUID。 It changes for every powershell session and the netsh binding needs to as well.它针对每个 powershell 会话而更改,并且 netsh 绑定也需要更改。

$appid = "appid={"+(get-host).InstanceId.guid+"}" $appid = "appid={"+(get-host).InstanceId.guid+"}"

$certhash = ls Cert:\\LocalMachine\\my | $certhash = ls 证书:\\LocalMachine\\my | where {$ .EnhancedKeyUsageList -Match 'Server' -and $ .subject -match (hostname)}|sort-object $_.NotAfter|select -expand Thumbprint -last 1其中 {$ .EnhancedKeyUsageList -Match 'Server' -and $ .subject -match (hostname)}|sort-object $_.NotAfter|select -expand Thumbprint -last 1

$cmdline='netsh http add sslcert ipport=0.0.0.0:443 certhash=' + $certhash + ' "' + $appid + '"' $cmdline='netsh http add sslcert ipport=0.0.0.0:443 certhash=' + $certhash + '"' + $appid + '"'

netsh http delete sslcert ipport=0.0.0.0:443 netsh http 删除 sslcert ipport=0.0.0.0:443

Invoke-Expression $cmdline调用表达式 $cmdline

谷歌搜索“无法检索 cmdlet 的动态参数”将我带到这里,但我的问题是从命令行使用 powershell,答案是转义命令上的双引号......

I've got a problem with the same error.我遇到了同样错误的问题。 This happens when i'm trying to Add-WebBinding to my IIS site remotely, using Invoke-Command from different agent machines at time.当我尝试将 WebBinding 远程添加到我的 IIS 站点时,会发生这种情况,同时使用来自不同代理机器的 Invoke-Command。

It's worked for me, maybe it helps someone too:它对我有用,也许对某人也有帮助:

$Mutex = New-Object -TypeName System.Threading.Mutex($false, "Global\Mutex")    
if ($Mutex.WaitOne(300000)) {
   #For example
   #$Command = {
        #New-WebBinding -name $iis_site_name -Protocol https -HostHeader             
           #$iis_host_name -Port 443 -SslFlags 1
   #}
   #Invoke-Command -Command $Command
} else {
   Write-Warning "Timed out acquiring mutex!"
}
    
$Mutex.Dispose()

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

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