My CSV file has employee data and each person gets 2 codes, one for login and one for their positionID. To find their manager, I need to lookup the Reports to PositionID table as a cross reference. The problem I'm having is when I use Import-Csv
, the first user in the file is terminated and the main login ID is removed from the file. I think that's why the following hash table fails with "Index operation failed; the array index evaluated to null"?
I tried
$csvData = Get-Content -Path $Maincsv | Select-Object -Skip 2 |
Out-String | ConvertFrom-Csv
But this fails as well. How can I make adjustments to correctly build my table so it doesn't crash?
$csvData = Import-Csv "C:My.csv"
$PIDTable = @{}
$csvData | ForEach-Object {
$PIDTable[$_."Position ID"] = $_
}
Data:
PersonID Position ID Legal First Name Reports To Position ID
YQM000051 DIANE YQM000076
S9999991 YQM000052 CHARISSE YQM000076
S9999992 YQM000052 CHARISSE YQM000076
s9999993 YQM000052 CHARISSE YQM000076
s9999994 YQM000076 Bob YQM000071
So, trying to cross reference the PersonID from "Reports To Position ID" so that a PersonID could be found for someone's manager Position ID. Sorry for messy format. But can the blank PersonID at the start, mess the array up?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…