【发布时间】:2017-03-24 17:18:18
【问题描述】:
我有一个脚本,它主要执行以下操作:
$user = Get-ADUser $someUserName -Server $someCertServer -Properties *
$user.userCertificate |% { Set-ADUser $someUserName -Certificates @{Add=$_} }
它将证书数据从证书服务器复制到默认服务器。 $user.userCertificate 是 Microsoft.ActiveDirectory.Management.ADPropertyValueCollection 类型,$user.userCertificate[0] 是 System.Byte[] 类型。根据docs,我可以通过Byte[] 并且很高兴。通过在上述脚本中使用 foreach 运算符,我得到了 Byte[]。
但是,Powershell 失败并显示错误消息
参数证书要求集合中的所有值都属于同一类型
(并在 @{Add=$_} 下划线;该消息可能不是 100% 准确,因为我必须将其翻译成英文)。由于使用了 foreach 运算符,因此只有一种类型:Byte[]。该错误消息是什么意思?如何将证书推入 ADUser 对象?
我也尝试将 Byte[] 转换为证书对象,但最终得到相同的错误消息:
$cert = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($user.userCertificate[0])
Set-ADUser $someUserName -Certificates @{Add=$cert}
【问题讨论】:
标签: powershell active-directory