powershell 向内部证书颁发机构申请证书

网友投稿 886 2022-09-16

powershell 向内部证书颁发机构申请证书

powershell 向内部证书颁发机构申请证书

此篇文章仅作为知识积累和记录, 懂得都懂, 不懂的,看官网就可以懂

涉及到两个工具 ​​CertReq​​​ 和 ​​certutil​​

$certpath = "D:\CertRequest"$pfx_files_path = "D:\pfxfiles"$CA = "CA001.contoso.com\ROOTCA01"$certtemplate = "ServersTemplate"$requestfile = Get-Content "D:\CertRequest.txt"foreach ($requestcert in $requestfile){ $subjectname = $requestcert # Read-Host "what is the FQDN like abc.contoso.com?" #set certificate FQDN $inf_filefullpath = "$certpath\$subjectname.inf" $req_filefullpath = "$certpath\$subjectname.req" $cer_filefullpath = "$certpath\$subjectname.cer" $pfx_filefullpath = "$certpath\$subjectname.pfx" $pwd_filefullpath = "$certpath\$subjectname" + "pwd.txt" $cersn_exportpath = "$certpath\$subjectname" + "sn.txt" "[Version]" | Out-File -Append $inf_filefullpath 'Signature="$Windows NT$"' | Out-File -Append $inf_filefullpath "`n" | Out-File -Append $inf_filefullpath "[NewRequest]" | Out-File -Append $inf_filefullpath "Subject=CN=" + "`"" + $subjectname + "`"" | Out-File -Append $inf_filefullpath "KeyLength = 2048" | Out-File -Append $inf_filefullpath "Exportable = true" | Out-File -Append $inf_filefullpath "`n" | Out-File -Append $inf_filefullpath "[RequestAttributes]" | Out-File -Append $inf_filefullpath "CertificateTemplate=$certtemplate" | Out-File -Append $inf_filefullpath CertReq -New -f $inf_filefullpath $req_filefullpath CertReq -Submit -f -config $CA $req_filefullpath $cer_filefullpath certreq -accept $cer_filefullpath certutil -verify $cer_filefullpath | findstr -i number > $cersn_exportpath $SN = (Get-Content $cersn_exportpath).Substring(20) $pfxpwd = abc123 # set pfx file password certutil -f -p $pfxpwd -exportpfx $SN $pfx_filefullpath Get-Item -Path $pfx_filefullpath | Move-Item -Destination $pfx_files_path -Force #move result pfx file to pfxfiles directory}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:如何利用CSS选择器抓取京东网商品信息
下一篇:移动应用的动态发布是什么?Flutter移动应用开发实战——发布动态
相关文章

 发表评论

暂时没有评论,来抢沙发吧~