Closed scotthardwick closed 1 week ago
@scotthardwick
Is it a must that you have to utilize the pipeline?
No, you might also provide the LeftObject
with a parameter. Meaning:
Merge-Object -LeftObject $advisor_original -RightObject $advisor_update -on StudentID
Should be the same as:
$advisor_original | Merge-Object $advisor_update -on StudentID
But in your first example you aren't assigning (or piping) the results of the command $advisor_original | Merge-Object $advisor_update -on StudentID
to anywhere. In other words, I am not surprised that you get different results but I would actually expect the second one to work for you.
I just reconfirmed that everything works as expected using my own test data:
$Employee = ConvertFrom-SourceTable -ParseRightAligned ' # Install-Script -Name ConvertFrom-SourceTable
Id Name Country Department Age ReportsTo
-- ---- ------- ---------- --- ---------
1 Aerts Belgium Sales 40 5
2 Bauer Germany Engineering 31 4
3 Cook England Sales 69 1
4 Duval France Engineering 21 5
5 Evans England Marketing 35
6 Fischer Germany Engineering 29 4'
$Changes = ConvertFrom-SourceTable -ParseRightAligned '
Id Name Country Department Age ReportsTo
-- ---- ------- ---------- --- ---------
3 Cook England Sales 69 5
6 Fischer France Engineering 29 4
7 Geralds Belgium Sales 71 1'
$Employee | Merge $Changes -On Id | Format-Table # Using the pipeline
Id Name Country Department Age ReportsTo
-- ---- ------- ---------- --- ---------
1 Aerts Belgium Sales 40 5
2 Bauer Germany Engineering 31 4
3 Cook England Sales 69 5
4 Duval France Engineering 21 5
5 Evans England Marketing 35
6 Fischer France Engineering 29 4
7 Geralds Belgium Sales 71 1
Merge -Left $Employee -Right $Changes -On Id | Format-Table # Using parameters
Id Name Country Department Age ReportsTo
-- ---- ------- ---------- --- ---------
1 Aerts Belgium Sales 40 5
2 Bauer Germany Engineering 31 4
3 Cook England Sales 69 5
4 Duval France Engineering 21 5
5 Evans England Marketing 35
6 Fischer France Engineering 29 4
7 Geralds Belgium Sales 71 1
For both examples you, might either first assign the result and that export it to a csv
or directly pipe (... | Export-Csv ...
) it to a csv
:
$advisor_original | Merge-Object $advisor_update -on StudentID |
Export-Csv 'C:\Users\Downloads\advising\advisor_20252_completewithupdate.txt'
or:
$Result = $advisor_original | Merge-Object $advisor_update -on StudentID
$Result | Export-Csv 'C:\Users\Downloads\advising\advisor_20252_completewithupdate.txt'
or:
Merge-Object -LeftObject $advisor_original -RightObject $advisor_update -on StudentID |
Export-Csv 'C:\Users\Downloads\advising\advisor_20252_completewithupdate.txt'
or:
$Result = Merge-Object -LeftObject $advisor_original -RightObject $advisor_update -on StudentID
$Result | Export-Csv 'C:\Users\Downloads\advising\advisor_20252_completewithupdate.txt'
Please provide me with a Minimal, Reproducible Example including sample data, if it still doesn't work for you.
Great and very helpful cmdlet. Thank you for coding and sharing!
I have one question. Is it a must that you have to utilize the pipeline? The first example below works perfectly, the second does not. Perhaps I am doing something wrong?
Example One $advisor_original | Merge-Object $advisor_update -on StudentID $advisor_original | Export-Csv 'C:\Users\Downloads\advising\advisor_20252_completewithupdate.txt'
Example Two $advisor_revised = Merge-Object -LeftObject $advisor_original -RightObject $advisor_update -on StudentID $advisor_revised | Export-Csv 'C:\Users\Downloads\advising\advisor_20252_completewithupdate.txt'
Using VERSION 3.8.3