简体   繁体   English

从Active Directory说明中拉出名称

[英]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.

相关问题 Powershell不会从Active Directory中提取所有计算机名称 - Powershell won't pull every computer name from Active Directory 如何让 psloggedon 从 Active Directory 中提取? - How can I get psloggedon to pull from Active Directory? 提取Active Directory用户信息 - Pull Active Directory user information 我需要从Active Directory中提取一些数据。 我想要一个AD用户列表,其姓氏字段的姓氏后面有“ PA” - I need a pull some data from Active Directory. I want a list of all the users in AD whose last name field has “PA” after their last name Powershell命令在Active Directory中获取描述内容 - Powershell command to get Description content in Active Directory 检索Active Directory计算机说明时遇到问题 - Trouble retrieving Active Directory computer description 如何从Active Directory获取组名和EmployeeID? - How to get group name and EmployeeID from Active Directory? PowerShell 中的正则表达式从 Active Directory 中的 Managedby 属性获取城市名称 - Regex in PowerShell to get the city name from the Managedby property in Active Directory 使用来自csv的powershell删除活动目录samaccount名称中的空白区域 - remove white space in active directory samaccount name with powershell from csv 如何在 PowerShell 中从 csv 查找 Active Directory 组名称? - How to look for Active Directory group name from csv in PowerShell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM