简体   繁体   English

Powershell脚本涉及AD用户和luhn算法

[英]Powershell script involving AD users and luhn algorithm

I'm a Powershell newbie, and I need help with a script.我是 Powershell 新手,我需要脚本方面的帮助。 I need to list all AD users with their employee ID, and I need a csv with a column which will state if the Employee ID is true or false according to Luhn algorithm test.我需要列出所有 AD 用户及其员工 ID,并且我需要一个 csv,如果根据 Luhn 算法测试员工 ID 为真或假,则该列将为 state。 I have this script:我有这个脚本:

import-module -Name ActiveDirectory

$SearchBaseOU = "OU=---,DC=---,DC=---"

$ADusers = Get-ADUser -Filter {Enabled -eq $True} -SearchBase $SearchBaseOU -Properties EmployeeID,CanonicalName,EmployeeNumber | 
   Where {$_.EmployeeID -eq "123456789"} | 
   Select-Object samAccountName, Name , EmployeeID, EmployeeNumber,@{name="OU";expression={(($_.CanonicalName.split('/'))[0..($_.CanonicalName.split('/').Count-2)]) -join '/'}}

$ADusers | Export-Csv .\EnabledInactiveUsers.csv -Force -NoTypeInformation -Encoding UTF8

This script lists all AD users with employee ID which equals to "123456789".此脚本列出了员工 ID 等于“123456789”的所有 AD 用户。 I also found this script online:我也在网上找到了这个脚本:

https://www.powershellgallery.com/packages/gibbels-algorithms/1.0.3/Content/scripts%5Cluhn%5CTest-LuhnValidation.ps1 https://www.powershellgallery.com/packages/gibbels-algorithms/1.0.3/Content/scripts%5Cluhn%5CTest-LuhnValidation.ps1

which tests if the ID is true or false.它测试 ID 是真还是假。

My question is - How do I take the luhn algorithm function and add it to the original script above to make the test and export the results into true or false statements?我的问题是 - 如何采用 luhn 算法 function 并将其添加到上面的原始脚本中以进行测试并将结果导出为 true 或 false 语句?

Thanks!谢谢!

You can use PowerShell Calculated Properties您可以使用 PowerShell 计算属性

For Example, see the last property in the select: "IsLuhn" like you used in the CanonicalName property in your example, Add the Luhn function from the link to your code first.例如,请参阅 select 中的最后一个属性:“IsLuhn”,就像您在示例中的 CanonicalName 属性中使用的那样,首先将链接中的 Luhn function 添加到您的代码中。

$ADusers = Get-ADUser[... -Properties EmployeeID,CanonicalName,EmployeeNumber ...] | 
Select EmployeeID,CanonicalName,EmployeeNumber,
@{N="IsLuhn";E={Test-LuhnValidation $_.EmployeeID}}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM