小编Rob*_*ton的帖子

从powershell创建自签名的iis ssl证书

我需要从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管理器手动创建证书,其余代码工作正常.

谢谢你的帮助!

iis powershell ssl iis-7 ssl-certificate

9
推荐指数
1
解决办法
5794
查看次数

如何在PowerShell中运行appCmd以将自定义标头添加到默认网站

请帮我弄清楚如何正确地转义参数,以便在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)

powershell iis-7 escaping p3p appcmd

5
推荐指数
1
解决办法
8934
查看次数

标签 统计

iis-7 ×2

powershell ×2

appcmd ×1

escaping ×1

iis ×1

p3p ×1

ssl ×1

ssl-certificate ×1