首页 > 解决方案 > 尝试在电话便笺中添加创建日期并输入当前日期,但只能获得“创建日期”

问题描述

使用下面的代码,我试图添加一个不是“创建于”,然后给出当前日期,但日期不填充。提前致谢...

Get-ADuser -Identity $username -Properties info |
ForEach-Object{
    $info = $_.Info
    $_|Set-ADuser -Replace @{info="$Info`n Created on $date"}
}

标签: powershellactive-directory

解决方案


您尚未$date在脚本中的任何地方定义。尝试以下操作:

Get-ADuser -Identity $username -Properties info |
ForEach-Object{
    $info = $_.Info
    $date = Get-Date
    $_|Set-ADuser -Replace @{info="$Info`n Created on $date"}
}

推荐阅读