2014-02-05 43 views
7

我需要从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 

结果

它说新SelfSignedCertificate不能用于该行被发现。如果我通过IIS管理器手动创建证书,其余的代码工作正常。

感谢您的帮助!

+1

从[此帖](http://stackoverflow.com/questions/12463297/using-powershell-to-create-self-signed-certificate? rq = 1)是[指向TechNet文章的链接](http://social.technet.microsoft.com/wiki/contents/articles/16226.quick-start-guide-for-integrating-a-single-forest- on-premises-active-directory-with-windows-azure-ad.aspx),它可以帮助你。 – admdrew

回答

10

我得到它的工作这样

Import-Module WebAdministration 

    Set-Location IIS:\SslBindings 

    New-WebBinding -Name "Default Web Site" -IP "*" -Port 443 -Protocol https 

    $c = New-SelfSignedCertificate -DnsName "myexample.com" -CertStoreLocation cert:\LocalMachine\My 

    $c | New-Item 0.0.0.0!443 
+0

对于任何遇到此解决方案的用户,首先需要导入Web管理模块,因此,“Import-Module WebAdministration”后面跟着“Set-Location IIS:\ SslBindings” – northerncodemonkey