Netwrix 1Secure 提供跨数据和身份的统一可见性——免费试用14天,享有完全访问权限。开始免费试用

资源中心操作指南

如何使用 PowerShell 或 Netwrix Auditor 在 Active Directory 中查找非活动用户

如何使用 PowerShell 或 Netwrix Auditor 在 Active Directory 中查找非活动用户

原生解决方案

先决条件:在运行以下任何脚本之前,你需要使用以下命令导入 Active DirectoryPowerShell 模块:

      Import-Module ActiveDirectory
      
  • 在域控制器上打开 Windows PowerShell ISE。
  • 要获取 90 天或更长时间处于非活动状态的用户,请运行以下 PowerShell 脚本之一:

使用 Search-ADAccount cmdlet:

      Search-ADAccount –AccountInActive -UsersOnly –TimeSpan 90:00:00:00 –ResultPageSize 2000 –ResultSetSize $null |?{$_.Enabled –eq $True} | Select-Object Name, SamAccountName, DistinguishedName| Export-CSV “C:\Temp\InactiveUsers.CSV” –NoTypeInformation
      

使用 Get-ADUser cmdlet:

      $date= (get-date).AddDays(-90)

Get-ADUser-Filter {LastLogonDate-lt $date} -Property Enabled|Where-Object {$_.Enabled -like “true”} |SelectName,SamAccountName,DistinguishedName|Export-CSV “C:\Temp\InactiveUsers.CSV” -NoTypeInformation
      

如有需要,可通过从上述脚本中删除 “Select-Object Name” 这部分管道来生成包含大量用户信息的报告。

  • 在 MS Excel 中打开脚本生成的 CSV 文件:
Image

Netwrix Auditor for Active Directory

  • 运行 Netwrix Auditor → 转到“Reports”→ 展开“Active Directory”部分 → 进入“Active Directory ­– State-in-Time”→ 选择“User Accounts”→ 点击“View”。
  • 将“Days Inactive”参数设置为所需的时间范围(例如 90 天)→ 点击“View Report”。
Image
  • 要保存报告,请点击“Export”按钮 → 从下拉菜单中选择格式 → 点击“Save”。

分享到