【发布时间】:2018-07-18 01:20:54
【问题描述】:
我目前正在创建一个 PowerShell 脚本来扫描 Active Directory 中去年未登录的用户。
Import-Module ActiveDirectory
$DaysInactive = 365
$InactiveDate = (Get-Date).AddDays(-($DaysInactive))
$Users = Get-ADUser -SearchScope OneLevel -SearchBase "ou=staff,ou=brummitt,dc=DUNELAND,dc=LOCAL" -Filter { LastLogonDate -lt $InactiveDate } -Properties LastLogonDate |
Select-Object @{Name="Username";Expression={$_.SamAccountName}},
Name, LastLogonDate, DistinguishedName
$Users | Export-Csv C:\Temp\InactiveUsers.csv -NoTypeInformation
如果您看到 users 变量,您会看到其中有一个学校名称和一个教职员工 ou。我们对我们地区的所有建筑物都有这个约定。如何以员工 OU 为第二级扫描所有第一级 OU?
我尝试将 Searchbase 更改为此 -SearchBase "ou=staff,ou=*,dc=DUNELAND,dc=LOCAL",但收到此错误:
【问题讨论】:
标签: powershell active-directory