广告用户禁用的日期处于扩展状态,需要基于此删除用户

发布于 2025-01-24 03:59:01 字数 500 浏览 0 评论 0原文

我们有一个管理人员的第三方LDAP系统。代表实际员工的广告用户是由此LDAP系统的提要创建和维护的。我们希望将用户在LDAP系统中禁用的日期发送到特定的AD用户属性,例如ExtentionAttribute9。

从那里,我将尝试Get-Aduser搜索扩展名的日期以上的日期超过90天。当然,问题是,这个扩展的属性将包含一个字符串值,而我似乎无法将其读取为日期。

我可以这样做是为了使用户在90天前创建用户,我希望我可以为填充日期的扩展属性做同样的事情:

$Date = [DateTime]::Today.AddDays(-90)

get-aduser -filter {created -lt $Date} -SearchBase "OU=User_Test,DC=foo,DC=com"

我尝试了一些事情,包括有外部帮助,但可能没有什么值得在这里发布的什么都没有真正接近。

如果我无法工作,我将搜索残疾人的用户,但没有登录超过90天,但是根据残疾日期进行此操作将更加确定。

We have a third party LDAP system managing people. AD users that represent actual employees are created and maintained by a feed from this LDAP system. We would like the date that a user is disabled in the LDAP system to be sent to a particular AD user attribute, for example extentionAttribute9.

From there I would try get-aduser to search extentionAttribute9 for ones with a date older than 90 days. The problem of course is that this extended attribute would contain a string value and I can't seem to get that read as a date.

I can do this to get users created more than 90 days ago and I wish I could do the same for the extension attribute populated with the date:

$Date = [DateTime]::Today.AddDays(-90)

get-aduser -filter {created -lt $Date} -SearchBase "OU=User_Test,DC=foo,DC=com"

I've tried a few things, including with outside help, but probably nothing worth posting here as nothing has really come close.

If I can't get this to work, I'll search for users who are disabled and haven't logged in for more than 90 days, but doing it based on a disabled date would be more definitive.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贩梦商人 2025-01-31 03:59:02

感谢您提供格式。

由于这种格式不仅可以与DateTime的简单铸件一起使用。我们需要按原样解析并将其转换为日期时间。从那里将其施放到“ yyyy-mm-dd”作为格式的字符串。

编辑:
评论中的错误代码是由于“:”。由于修剪的变量不包含':'它正在丢弃错误。

从使用'.trim()'(这只会将白空间)转换为'-replace'\ w''。这样做可以使我们更轻松地从变量中删除非alphanumeric字符。

让我知道这是否对您有用。

$Date = [DateTime]::Today.AddDays(-90)
$Pattern = '[^a-zA-Z]'
Get-ADUser -Filter * -SearchBase "OU=User_Test,DC=foo,DC=com" | 
   Where {([datetime]::ParseExact($($_.extensionAttribute9 -replace '\W'), 'yyyyMMdd', $null).ToString('yyyy-MM-dd')) -lt $Date}

Thanks for providing the format.

Since that format won't work with just a simple cast to datetime. We need to parse it as is and convert it to datetime. From there cast it to string with 'yyyy-MM-dd' as the format.

EDIT:
The error code in the comment is due to ':' in .Trim. As the variable being trimmed does not contain ':' it is throwing the error.

Changed from using '.Trim()' (this would only remove white space) to '-replace '\W' '. Doing this allows us to more easily remove non-alphanumeric characters from the variable.

Let me know if this works for you.

$Date = [DateTime]::Today.AddDays(-90)
$Pattern = '[^a-zA-Z]'
Get-ADUser -Filter * -SearchBase "OU=User_Test,DC=foo,DC=com" | 
   Where {([datetime]::ParseExact($($_.extensionAttribute9 -replace '\W'), 'yyyyMMdd', $null).ToString('yyyy-MM-dd')) -lt $Date}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文