【问题标题】:I Can't modify AD user custom attribute via powershell我无法通过 powershell 修改 AD 用户自定义属性
【发布时间】:2020-04-15 06:21:40
【问题描述】:

我正在尝试更新活动目录用户信息,并向用户添加了一个新的自定义属性,新属性调用证书,并且我能够通过 powershell Set-Aduser 修改所有属性,但我的新属性除外。 这是我的powershell代码和错误: 代码:

$user = Get-ADUser -Filter "SamAccountName -eq '$($Object.UserName)'" -Server $server -Credential $credential
     Set-ADUser -Identity $user -HomePage $Object.HomePage `
                                  -Description $Object.Description`
                                  -Title $Object.Title`
                                  -Officephone $Object.PhoneNumber`
                                  -Mobilephone $Object.Mobile`
                                  -Postalcode $Object.PostalCode`
                                  -City $Object.City`
                                  -State $Object.State`
                                  -Streetaddress $Object.StreetAddress`
                                  -Department $Object.Department`
                                  -Company $Object.Company
                                  -Certificat $Object.Certificat

错误:

Set-ADUser: Unable to bind the "Certificates" parameter. Unable to convert the value "Study Study" from type "System.String" to type
"System.Collections.Hashtable".
Au caractère C:\Users\test\Desktop\PP\AdInfoUpdater.ps1:40 : 43
+                               -Certificat $Object.Certificat
+                                           ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument : (:) [Set-ADUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.SetADUser

【问题讨论】:

    标签: powershell active-directory attributes


    【解决方案1】:

    如果是自定义属性,则需要使用 -Replace 参数或 -Add 参数 例如

    Set-AdUser userid -Replace @{'certificat'='CertificateStringValue'}
    

    当 PowerShell 看到 -Certificates(甚至是 -Certif 之类的缩短版本)时,它会将其解析为引用 AD 中的 userCertificate 属性

    【讨论】:

      猜你喜欢
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-09
      • 1970-01-01
      相关资源
      最近更新 更多