[英]Pull out name from Active Directory description
I'm not sure if this will work, but I figured I'd throw it out here to see if there are any ideas. 我不确定这是否行得通,但我想我会把它扔出去看看是否有任何想法。 We have an OU in Active Directory for external users.
我们在Active Directory中为外部用户提供了一个OU。 These users have accounts that expire every 6 months.
这些用户的帐户每6个月到期一次。 I've written a script to run a report every month and collect the accounts that are expiring into a text file so that I have an easy-to-read list.
我编写了一个脚本,每个月运行一次报告,并将即将过期的帐户收集到一个文本文件中,这样我便获得了一个易于阅读的列表。 However, I really want to group these by the person who requested the account for the external user, because I have to email the requester and see if the account should be extended.
但是,我确实想按为外部用户请求帐户的人员将这些分组,因为我必须通过电子邮件发送给请求者,并查看是否应扩展该帐户。
In the description for the external user's account, among other things, is the phrase "Requested by " followed by the name of the employee I need to email. 在外部用户帐户的说明中,除其他外,短语“ Requested by”后面紧跟我需要通过电子邮件发送的员工的姓名。 I really want to sort my script output by these names, so it's easier to see who I need to email (and eventually I'd like to automate it all so that an email is just sent when an account is expiring).
我真的很想按这些名称对脚本输出进行排序,以便更轻松地查看需要向谁发送电子邮件(最终我希望将其全部自动化,以便在帐户到期时才发送电子邮件)。
So basically, I need PowerShell to look at the string in the description attribute, find the phrase "requested by" and then list the name. 因此,基本上,我需要PowerShell来查看description属性中的字符串,找到短语“ requested by”,然后列出名称。 Some very terrible pseudocode might look like:
一些非常糟糕的伪代码可能看起来像:
If substring == "requested by" Go one more character print each character until space go one more character (skipping the space) print each character until space
I know this is a long shot. 我知道这是一个远景。 Any tips are welcome.
欢迎任何提示。
EDIT: Here is an example of a description 编辑:这是一个描述的例子
PROJECT - Requested by John Smith 1/8/16, Expires 12/31/16 项目-约翰·史密斯(John Smith)请求1/8/16,于12/31/16到期
You can use a regular expression pattern to grab the names from the Description
attribute: 您可以使用正则表达式模式从
Description
属性获取名称:
$User = Get-ADUser external.user -Properties description
if($User.Description -match 'requested by (?<Name>\S+ \S+) ') {
$EmployeeName = $Matches['Name']
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.