将日期添加到扩展属性中



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

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

参数是下面使用的参数。

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

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也将始终有效,因此您可能只想使用它。

最新更新