广告用户禁用的日期处于扩展状态,需要基于此删除用户
我们有一个管理人员的第三方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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢您提供格式。
由于这种格式不仅可以与DateTime的简单铸件一起使用。我们需要按原样解析并将其转换为日期时间。从那里将其施放到“ yyyy-mm-dd”作为格式的字符串。
编辑:
评论中的错误代码是由于“:”。由于修剪的变量不包含':'它正在丢弃错误。
从使用'.trim()'(这只会将白空间)转换为'-replace'\ w''。这样做可以使我们更轻松地从变量中删除非alphanumeric字符。
让我知道这是否对您有用。
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.