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

Dav*_*ted 9 windows powershell batch-file iis-8 lets-encrypt

我们正在使用Windows 2012 Server R2.

我们正在尝试自动创建LetsEncrypt证书.我们正在使用LetsEncrypt-Win-Simple(https://github.com/Lone-Coder/letsencrypt-win-simple).

一旦创建了证书(通过LetsEncrypt.exe),我们就会调用一个.bat脚本(使用--script和--scriptparameters标志).这将运行powershell.exe并尝试创建必要的IIS绑定..bat文件中的行是:

powershell.exe -file c:\temp\SSLIISBinding.ps1 %1 %2 %3 %4
Run Code Online (Sandbox Code Playgroud)

%1-4是LetsEncrypt传入的args.在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
Run Code Online (Sandbox Code Playgroud)

args传入.bat罚款,因为我们输出它们并且它们正确显示.

如果我们自己运行.bat文件,它就能完美运行.如果它被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
Run Code Online (Sandbox Code Playgroud)

我用Google搜索过,有些人提到了32位对比64位PowerShell,但我尝试使用所有不同的powershell.exe.

任何人都遇到了这个问题,或者知道要解决.

如果我们直接从命令行调用.bat它可以正常工作,就像通过LetsEncrypt.exe调用一样.许可问题?powershell.exe错在?

use*_*407 12

那部分问题:

我用Google搜索,有些人提到了32位对比64位的PowerShell

已经是答案的一半了.如果PowerShell进程的位数与操作系统的位数不匹配,则某些命令无法正常运行.因此,您需要运行powershell.exe,该%windir%\System32\WindowsPowerShell\v1.0\目录位于此目录中.但是本文档主题中描述了一个小问题:

在大多数情况下,只要32位应用程序尝试访问%windir%\ System32,就会将访问权限重定向到%windir%\ SysWOW64.

因此,如果64位操作系统上的32位程序调用%windir%\System32\WindowsPowerShell\v1.0\powershell.exe,它实际上将从此处调用32位版本的PowerShell %windir%\SysWOW64\WindowsPowerShell\v1.0\而不是64 位版本.要从32位应用程序实际调用64位PowerShell,您需要使用此技巧:

32位应用程序可以通过%windir%\ Sysnative替换%windir%\ System32来访问本机系统目录.WOW64将Sysnative识别为一个特殊别名,用于指示文件系统不应重定向访问.