【发布时间】:2019-08-17 21:49:00
【问题描述】:
我需要更新存储在用户 AD 帐户中的一组证书。
我有这个:
$allProfileRawCerts = Get-ADUser -Server example.com -Filter {EmailAddress -eq $Mail} -Property Certificates
这给了
Certificates : {System.Security.Cryptography.X509Certificates.X509Certificate, System.Security.Cryptography.X509Certificates.X509Certificate,
System.Security.Cryptography.X509Certificates.X509Certificate}
DistinguishedName : <>
Enabled : True
GivenName : <>
Name : <>
ObjectClass : user
ObjectGUID : <>
SamAccountName : <>
SID : <>
Surname : <>
UserPrincipalName : <>
我找到了Powershell Set-ADUser userCertificate parameter type error,它提供了“添加”操作:
$certUser.Usercertificate | ForEach-Object{
Set-ADUser "ME" -certificate @{Add=[System.Security.Cryptography.X509Certificates.X509Certificate]$_}
}
但是,我需要的不是添加,而是更新 - 根据条件删除一些证书,然后添加新证书。
一种方法(我认为)是从用户配置文件中删除所有证书,创建新数组并更新 - 但我真的非常不喜欢在非原子操作中删除有效数据。
另外,问题(至少对我而言)是我无法过滤(相当基本的)X509Certificate,但我必须先转换为 X509Certificate2:
$allProfileSMIMECerts = $allProfileRawCerts.Certificates |
foreach {New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $_} |
Where-Object { $_.EnhancedKeyUsageList.FriendlyName -eq "Secure Email" }
我需要的是:
- 获取所有证书的列表。
- 删除所有
$_.EnhancedKeyUsageList.FriendlyName -eq "Secure Email"为真的。 - 添加新证书。
如何以一种好的方式做到这一点?
【问题讨论】:
-
AD 和 Exchange 中的许多项目需要清空并重新填充以进行更新。如果您提取的方法没有并且没有更新,那么您推测的就是您的选择。
标签: powershell active-directory