【问题标题】:How to get the inactive user in active directory using Powershell?如何使用 Powershell 在活动目录中获取非活动用户?
【发布时间】:2018-02-12 23:16:03
【问题描述】:

如何使用 Powershell for Windows 2012 服务器在 Active Directory 中获取带有时间戳的非活动用户?

【问题讨论】:

标签: windows powershell server


【解决方案1】:

这是一个让您入门的示例(未经测试,但应该可以在 2012 年使用):

$DaysInactive = 30 
$time = (Get-Date).Adddays(-($DaysInactive))
Get-ADUser -Filter {LastLogonTimeStamp -lt $time -and enabled -eq $true} -Properties LastLogonTimeStamp | 
select Name, @{l='LastLogonTimestamp'; E={[DateTime]::FromFileTime($_.LastLogonTimestamp)}} | sort name

此脚本将获取 30 天内未更新 lastlogontimestamp 属性的所有帐户。

【讨论】:

  • 请注意,根据您对“非活动”的定义,lastlogontimestamp 可能不是一个好主意,因为在默认环境中它最多可以关闭2 weeks
  • 请务必注意,lastLogontimeStamp 属性的预期用途是帮助识别非活动计算机和用户帐户。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多