简体   繁体   English

更改 Active Directory 中的 LastLogonDate 属性

[英]Change LastLogonDate property in Active Directory

I am writing a script to disable old workstation objects (and I have to remake the wheel due to some unique things on my system).我正在编写一个脚本来禁用旧的工作站对象(由于我的系统上的一些独特的东西,我必须重新制作轮子)。 I'd like to make some test computer objects with known LastLogonDate to validate my script.我想使用已知的 LastLogonDate 制作一些测试计算机对象来验证我的脚本。

How can I, preferably just with PowerShell, set the LastLogonDate property to what I want it to be?我怎样才能,最好只使用 PowerShell,将 LastLogonDate 属性设置为我想要的? I'd prefer it to be in PowerShell so I can include the necessary changes in order self-test my code when it runs.我更喜欢它在 PowerShell 中,以便我可以包含必要的更改,以便在运行时对我的代码进行自我测试。 I am also heavily restricted on what programs can be placed on the network.我也严格限制哪些程序可以放在网络上。

I haven't found a pure PowerShell solution, and TechNet indicates that Set-ADComputer doesn't have that functionality.我还没有找到纯粹的 PowerShell 解决方案,TechNet 指出 Set-ADComputer 没有该功能。 In desperation I've tried running ADSIedit on a domain controller to set LastLogon and LastLogonTimestamp, but get error 0x209a (attribute is owned by the Security Accounts Manager).无奈之下,我尝试在域控制器上运行 ADSIedit 来设置 LastLogon 和 LastLogonTimestamp,但得到错误 0x209a(属性归安全帐户管理器所有)。

Worst case scenario, I can use a previously disabled workstation but that workaround is getting a lot of frowns from my security folks.最坏的情况是,我可以使用以前禁用的工作站,但这种解决方法让我的安全人员很不高兴。

Thank you.谢谢你。

Edit:编辑:

If I can figure out how to get around that "error 0x209a (attribute is owned by the Security Accounts Manager" issue, I think I can use the following PowerShell to set it:如果我能弄清楚如何解决“错误 0x209a(属性归安全帐户管理器所有”问题),我想我可以使用以下 PowerShell 来设置它:

Get-ADComputer -Identity <ComputerName> -Server <DomainController> | Set-ADObject -DisplayName <ComputerName> -Replace @{LastLogon=<NewTimeStamp>}

Where NewTimeStamp is the tick count of the date you want to set.其中 NewTimeStamp 是您要设置的日期的滴答计数。

Do not modify!不要修改! BothLastLogon andLastLogonTimeStamp are system-owned attributes and even if you found a way to bypass the restriction, you would most likely break the replication of the object. LastLogonLastLogonTimeStamp都是系统拥有的属性,即使您找到了绕过限制的方法,也很可能会破坏对象的复制。

There's nothing wrong with disabling and moving old unused computer objects.禁用和移动旧的未使用的计算机对象并没有错。 Your security folks would however hate you if you broke AD by doing unsupported modifications.但是,如果您通过不支持的修改破坏了 AD,您的安全人员会讨厌您。

LastLogonDate is a virtual/calculated property created by the AD-module for easy access to a datetime-converted property of for the LastLogonTimeStamp -attribute. LastLogonDate是由 AD 模块创建的虚拟/计算属性,用于轻松访问LastLogonTimeStamp属性的日期时间转换属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM