将日期添加到扩展属性

时间:2018-03-19 11:47:26

标签: powershell active-directory attributes

我正在尝试将日期添加到PowerShell AD帐户的扩展属性中,但会收到错误消息:

  

无效的类型:System.Management.Automation.PSObject

,参数是下面使用的参数。

Set-ADUser -Identity tst_lawsonja -Add @{extensionAttribute15 = Get-Date}

1 个答案:

答案 0 :(得分:1)

gvee是对的。 extensionAttribute属性仅限文本。将日期转换为文本,然后尝试设置它,如下所示:

Set-ADUser -Identity tst_lawsonja -Add @{extensionAttribute15 = (Get-Date).ToString()}

请注意Add仅在尚未设置属性时才有效。如果是,则需要使用Replace

Set-ADUser -Identity tst_lawsonja -Replace @{extensionAttribute15 = (Get-Date).ToString()}

Replace将始终有效,即使未设置该属性,因此您可能只想使用该属性。

相关问题