洞察探索如何利用兼容微信生态的小程序容器,实现跨平台开发,助力金融和车联网行业的数字化转型。
752
2022-09-18
Powershell 添加/删除证书
对于Server 2008 系列证书的删除和添加需要借助- 类进行
移除证书
$thumbprint = gci Cert:\LocalMachine\my |?{$_.Subject -eq "CN=server01.contoso.com"}$store = New-Object System.Security.Cryptography.x509Certificates.x509Store("My","LocalMachine")$store.Open("ReadWrite")$removecert = $store.Certificates |?{$_.Thumbprint -eq $thumbprint}$store.Remove($removecert)$store.Close()
添加证书
function Import-PfxCertificate { param([String]$certPath,[String]$certRootStore = "localmachine",[String]$certStore = "My",$pfxPass = $null) $pfx = new-object System.Security.Cryptography.X509Certificates.X509Certificate2 if ($pfxPass -eq $null) { $pfxPass = ConvertTo-SecureString "123" -AsPlainText -Force } $pfx.import($certPath,$pfxPass,"Exportable,PersistKeySet") $store = new-object System.Security.Cryptography.X509Certificates.X509Store($certStore,$certRootStore) $store.open("MaxAllowed") $store.add($pfx) $store.close() }Import-PfxCertificate "C:\certs\$fqdn.pfx" "LocalMachine" "My"
对于Server 2012 及以上可以通过Powershell 3.0 内核自带的命令
添加证书
$certpath = "C:\server01.pfx"Import-PfxCertificate -FilePath $certpath -CertStoreLocation Cert:\LocalMachine\My -Password (ConvertTo-SecureString '123' -AsPlainText -Force)
移除证书
$expirecert = Get-ChildItem Cert:\LocalMachine\My |?{$_.Subject -eq 'CN=server01'}$thumbprint = $expirecert.ThumbprintRemove-Item "Cert:\LocalMachine\my\$thumbprint" -Confirm:$false -Force # remove certificate from cert store
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~