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