0

我正在尝试检索帐户在 7 天后到期的所有 AD 用户的列表。不是“内”。我发现一个类似的问题已经在这里得到了回答,但该脚本仅适用于内部。我下面的脚本有效,但检索将在“7 天内”到期的帐户。我尝试了许多不同的方法,但都不起作用。

$List = Search-Adaccount -AccountExpiring -Timespan 07.00:00:00 | 
Where-Object {$_.DistinguishedName -like "*OU=test,DC=Domain,DC=com"}

$List | export-csv "c:\temp\expiring_accounts.csv"
4

2 回答 2

1

Adapting Shay Levy's answer on this similar question, can you add another condition to the Where-Object to put both an upper and lower bound on the expiration date?

$NeverExpires = 9223372036854775807;
$ExpireMin = (Get-Date).AddDays(6);
$ExpireMax = (Get-Date).AddDays(8);

Get-ADUser -Filter * -Properties accountExpires | 
Where-Object {$_.accountExpires -ne $NeverExpires  `
-and [datetime]::FromFileTime([int64]::Parse($_.accountExpires)) -lt $ExpireMax `
-and [datetime]::FromFileTime([int64]::Parse($_.accountExpires)) -gt $ExpireMin }

I don't presently have any expiring accounts in the AD environment I have access to, so I don't know if this will work exactly as you're asking.

于 2013-09-16T18:33:02.497 回答
1

试试adsysnet的免费 Active Directory 报告。它们为广告对象提供了一些有用的报告(用户、计算机、ou、联系人、组等)和功能(移动、删除、重置、解锁、发送邮件等)。

免费的 Active Directory 报告

于 2013-09-17T06:20:12.930 回答