我需要从PowerShell脚本创建一个新的自签名IIS SSL证书,作为自动安装的一部分.
这是我尝试过的:
Import-Module WebAdministation
New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https
New-SelfSignedCertificate -Subject Fluency -DnsName $computerName.$domainName -CertStoreLocation cert:\LocalMachine\My
Get-ChildItem cert:\LocalMachine\My | where { $_.Subject -match "CN\=$Computername\.$DomainName" } | select -First 1 | New-Item IIS:\SslBindings\0.0.0.0!443
Run Code Online (Sandbox Code Playgroud)
结果
它表示无法找到该行的New-SelfSignedCertificate.如果我通过IIS管理器手动创建证书,其余代码工作正常.
谢谢你的帮助!
请帮我弄清楚如何正确地转义参数,以便在PowerShell中调用appcmd时它们可以工作.
我的脚本看起来像这样:
$defaultWebSite = "Default Web Site"
$appCmd = "C:\windows\system32\inetsrv\appcmd.exe"
$addHeaderP3P = "set config ""$defaultWebSite"" -section:system.webServer/httpProtocol /+""customHeaders.[name='P3P',value='policyRef=`\`"/w3c/p3p.xml`\`",CP=`\`"DSP COR NID OUR COM PRE`\`"']`""
Write-Output "Here's the argument string: " $addHeaderP3P
Write-Output "`nInvoke Result:"
Invoke-Expression "$appCmd $addHeaderP3P"
Write-Output "`n& Result:"
& $appCmd --%"$addHeaderP3P"
Run Code Online (Sandbox Code Playgroud)
在powershell_ise中运行时输出为:
PS C:\Users\robert.bratton> D:\Junk\p3pheader.ps1
Here's the argument string:
set config "Default Web Site" -section:system.webServer/httpProtocol /+"customHeaders.[name='P3P',value='policyRef=\"/w3c/p3p.xml\",CP=\"DSP COR NID OUR COM PRE\"']"
Invoke Result:
Failed to process input: The parameter 'COR' must begin with a / or - (HRESULT=80070057).
& Result: …Run Code Online (Sandbox Code Playgroud)