I'm a Powershell newbie, and I need help with a script. 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. 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". I also found this script online:
which tests if the ID is true or false.
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?
Thanks!
CodePudding user response:
You can use PowerShell Calculated Properties
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.
$ADusers = Get-ADUser[... -Properties EmployeeID,CanonicalName,EmployeeNumber ...] |
Select EmployeeID,CanonicalName,EmployeeNumber,
@{N="IsLuhn";E={Test-LuhnValidation $_.EmployeeID}}