PowerShell中导出用户AD证书并存储在数据文件中的最佳方法是什么。
我可以获得用户证书:
$user = Get-ADuser "tester01"
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $user.usercertificate
我想将其导出到一个文件中,以便以后可以使用PowerShell将其导入到用户AD帐户中。
我该怎么做?
PKI颁发的用户证书在他们的计算机上。只需使用证书驱动器即可获取它们。获取PSDrive,获取ChildItem-路径证书:。请参阅帮助文件和帮助文件示例。
或者使用。。。
出口证书
模块:PKIClient
将证书从证书存储导出到文件中。
# Get specifics for a module, cmdlet, or function
(Get-Command -Name Export-Certificate).Parameters
(Get-Command -Name Export-Certificate).Parameters.Keys
Get-help -Name Export-Certificate -Examples
# Results
<#
$cert = (Get-ChildItem -Path
Export-Certificate -Cert $cert -FilePath c:certsuser.sst -Type SST
$cert = (Get-ChildItem -Path
Export-Certificate -Cert $cert -FilePath c:certsuser.cer
$cert = ( Get-ChildItem -Path
Export-Certificate -Cert $cert -FilePath c:certsuser.p7b -Type p7b
Get-ChildItem -Path cert:CurrentUsermy | Export-Certificate ûFilePath
#>
Get-help -Name Export-Certificate -Full
Get-help -Name Export-Certificate -Online
另请参阅:
https://www.powershellgallery.com/packages/CPolydorou.ActiveDirectory/1.7.0/Content/UserCertificates.psm1