Join-Object -Type AllInBoth & -RightProperties outputs empty value for JoinProperty
Question: How can below specified required result be achieved?
Data examples:
file1: hostname;IP Address s1;10.10.1.1 s3;10.10.1.3
file2: Hostname;exist s1;Y missing1;Y
Required result:
file3: hostname;IP Address;exist "s3";"10.10.1.3"; "s1";"10.10.1.1";"Y" "missing1";;"Y" I've tried:
$CSVfieldDelimiter =';'
# Get the files loaded into objects
$Object1 = Import-CSV file1 -Delimiter $CSVfieldDelimiter
$Object2 = Import-CSV file2 -Delimiter $CSVfieldDelimiter
# Dot source the file
. .\join-object.ps1
Join-Object -Left $Object1 -Right $Object2 `
-LeftJoinProperty Hostname `
-RightJoinProperty Hostname `
-RightProperties exist `
-Type AllInBoth |
Export-CSV $file3 -Delimiter $CSVfieldDelimiter -NoTypeInformation
but result is: file3: hostname;IP Address;exist "s3";"10.10.1.3"; "s1";"10.10.1.1";"Y" ;;"Y"
The problem is the columns selected for storage - missing the RightProperty "hostname". If you use "-Type=AllInBoth" then you will need to include the key (hostname) column from both tables. Make it: "-RightProperties hostname,exist" (without the quotes). Or just leave argument out to get all columns from that table. You already have all of the LeftProperties by default. If you want to clean up extra columns (only have one hostname column) then do a pass of the resulting joined object in memory - to copy the existing value from the secondary hostname column, where it exists, into the first hostname column (but don't copy the blanks) - before you save the data.