简体   繁体   English

Powershell-将Active Directory用户名与电子邮件地址进行比较

[英]Powershell - compare Active Directory usernames with e-mail address

I am currently trying to find all AD users that have been created using the model "firstname@domain.com" versus our new standard of "FirstInitialLastName@domain.com". 我目前正在尝试查找使用模型“ firstname@domain.com”与我们的新标准“ FirstInitialLastName@domain.com”创建的所有AD用户。 I'm using the Quest ActiveRoles modules, specifically Get-QADUser to pull down my user details: 我正在使用Quest ActiveRoles模块,特别是Get-QADUser来提取我的用户详细信息:

Get-QADUser -enabled -IncludedProperties PrimarySMTPAddress | ?{$_.Type -match "User"} | Select-Object FirstName,PrimarySMTPAddress ...

That gets me a list of user first names and their SMTP address. 这为我提供了用户名及其SMTP地址的列表。 Where I am stumped is how to compare the results. 我感到困惑的是如何比较结果。

I thought normalizing the values (either adding "@domain.com" to the first name string or stripping "@domain.com" from the SMTP string) and then doing a -ieq test would be the best approach. 我认为规范化值(将“ @ domain.com”添加到名字字符串中或从SMTP字符串中删除“ @ domain.com”)然后进行-ieq测试将是最好的方法。 I have found I can do the first with: 我发现我可以做的第一件事:

%{ $address=$($_.FirstName + "@domain.com";) }

But I can't figure out how to then test $address against the PrimarySMTPAddress string. 但是我不知道如何然后针对PrimarySMTPAddress字符串测试$ address。 I can create a second variable with: 我可以创建第二个变量:

%{ $smtp=$($_.PrimarySMTPAddress); }

and get the result: 并得到结果:

[PS] C:\>$addy -ieq $smtp
True

I'm just unclear how to do it all in stream so that I can process my tree at once. 我只是不清楚如何在流中完成所有操作,以便可以立即处理我的树。 If this is something that's just more suited to a script than a single line, that's fine too. 如果这比单行代码更适合脚本,那也很好。 Coming from the glorious world of BASH my brain just wanted to one-line it. 来自光荣的BASH世界,我的大脑只想把它排成一行。

Get-QADUser -Enabled -Email * -SizeLimit 0 | 
Where-Object {$_.Email.Split('@')[0] -eq $_.FirstName }

Try this: 尝试这个:

Get-QADUser -enable -IncludedProperties PrimarySMTPAddress |
? { $_.PrimarySMTPAddress -match ("^"+[regex]::escape("$($_.firstname)")+"@domain.com") }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过迭代从光盘向电子邮件添加多个附件 - Adding multiple attachments to e-mail from disc by iteration 通过迭代保存从电子邮件中提取的附件 - Save attachments extracted from e-mail by iterating 遍历熊猫数据框,将收件人和数据框插入Outlook电子邮件 - Loop through pandas dataframe, insert recipient and dataframe into Outlook e-mail 在单元格中使用内部颜色来选择要存储在字符串中的电子邮件地址 - Use interior color in cells to choose e-mail addresses to store in a string 使用 Powershell 计算每个 Active Directory 组的成员 - Counting member PER Active Directory Group using Powershell 如何在PowerShell中将所有Active Directory计算机读入阵列? - How can I read all Active Directory computers into an array in PowerShell? 列出Active Directory中组的所有子组(成员)-Powershell - List all Sub-Groups (members) of Groups in Active Directory - Powershell 比较While循环中数组中的元素-Powershell - Compare Elements in Array for While Loop - Powershell Powershell Foreach循环不循环遍历每个目录 - Powershell Foreach loop not looping through each directory wp_mail()循环发送,仅发送到最后一个地址 - wp_mail() in a loop, only sending to last address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM