Need to match 6 digits with 5 digits where just 0 is extra

$UserList = Import-Csv -Path "j:\testad.csv"
$UserData = Import-Csv -Path "j:\testswn.csv"
$Lookup = @{}
$UserData | ForEach-Object {$Lookup[$_.EmployeeID] = $_}
$UserList | Select-Object -Property `
      EmployeeID, Givenname, sn, EmailAddress, StreetAddress, City, State, Country, PostalCode, `
      @{n='Telephone'; e={$Lookup[$_.EmployeeID].Telephone}}, @{n='PersonalEmail'; e={$Lookup[$_.EmployeeID].PersonalEmail}} |
      Export-Csv -NoTypeInformation -Path "j:\testresult2.csv"


Everything is fine but the thing is in one CSV file for some Employees id they are in 6 digits and others in 5 digits, so there the matching result we are getting is incorrect.

Ex- If in my first CSV there are 2 records of Employee id - 123456, 034567 where as in second CSV file it is like- 123456, 34567(0 is not there), so how can we change the equate equation for employee ids so that we can match 6 digits employee id with 5 digits in second csv?

$UserData | ForEach-Object {$Lookup[$_.EmployeeID] = $_}
Aakash AggarwalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroCEOCommented:
Try this:
$UserData | ForEach-Object {$Lookup["0" +$_.EmployeeID] = $_}

Open in new window

0
footechCommented:
Since the leading "0" may only be present on some records, you would want to have padding out to the 6-character length.
Either of the following two should work.
$UserData | ForEach-Object {$Lookup[$_.EmployeeID.padleft(6,'0')] = $_}

$UserData | ForEach-Object {$Lookup.Add(($_.EmployeeID.padleft(6,'0')),$_)}

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aikimarkCommented:
Or cast the value as a number using [int] and do your comparisons numerically instead of text/string
0
Jose Gabriel Ortega CastroCEOCommented:
answered
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.