iRon7 / Join-Object

Combines two objects lists based on a related property between them.
MIT License
107 stars 13 forks source link

'-where' condition not work correctly if function imported via 'Import-module' #9

Closed Erikov-K closed 4 years ago

Erikov-K commented 4 years ago

Hello!

Thank you for you work! Your function help me every day! :-)

I found scenario in which work of function looks strange. When I using ' Import-Module -FullyQualifiedName $PathToModule' for import function 'Join-Object' I find a issue: '-where' condition not work correctly. If I placing your source code of your function directly into my script - all work fine! Version of a 'Join-Object' 3.0.6

Output with 'Import-module': lun-serial volume vol-state host-DiskNumber host-OperationalStatus ---------- ------ --------- --------------- ---------------------- QvaAo+E56ZNH cl_Cedar_WithAcessPath_SQL_T03_3 online QvaAo+E56ZNh cl_ExportMasterDB_Max_to_Dell_SQL_T03_2 online

Output with directly function definition: lun-serial volume vol-state host-DiskNumber host-OperationalStatus ---------- ------ --------- --------------- ---------------------- QvaAo+E56ZNH cl_Cedar_WithAcessPath_SQL_T03_3 online 11 Online QvaAo+E56ZNh cl_ExportMasterDB_Max_to_Dell_SQL_T03_2 online 34 Offline

Left and right arrays for join you can find below: $Left = @() $myobj = New-Object -TypeName PSObject Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'volume' -Value "cl_Cedar_WithAcessPath_SQL_T03_3" Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'vol-state' -Value "online" Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'lun-serial' -Value "QvaAo+E56ZNH" $Left += $myobj $myobj = New-Object -TypeName PSObject Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'volume' -Value "cl_ExportMasterDB_Max_to_Dell_SQL_T03_2" Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'vol-state' -Value "online" Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'lun-serial' -Value "QvaAo+E56ZNh" $Left += $myobj ` $Right = @() $myobj = New-Object -TypeName PSObject Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'lun-serial' -Value "QvaAo+E56ZNH" Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'host-DiskNumber' -Value "11" Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'host-OperationalStatus' -Value "Online" $Right += $myobj $myobj = New-Object -TypeName PSObject Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'lun-serial' -Value "QvaAo+E56ZNh" Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'host-DiskNumber' -Value "34" Add-Member -InputObject $myobj -MemberType 'NoteProperty' -Name 'host-OperationalStatus' -Value "Offline" $Right += $myobj Result = Join-Object -LeftObject $Left -RightObject $Right -JoinType Left -On lun-serial -where {$Left.'lun-serial' -ceq $Right.'lun-serial'} $Result | Format-Table`

iRon7 commented 4 years ago

Hello Erikov,

Thanks for your message. I just uploaded a new version (3.1.3) a few days ago that resolve an issue with the -Where object and outer joins (e.g. -JoinType Left), see: CHANGELOG

I am not sure if this resolves your issue but maybe you can test this first. The point is that although I have a lot of regression tests that I walk through before uploading a new version, I do not specifically test the script as a module... Please, let me know if this version resolves the issue.

Some other hints and options:

Erikov-K commented 4 years ago

Hello, iRon7! Thank you for a support! You gave me right advice: I started using 'Join-Object' via dot-sourcing instead of 'import-module' and all worked fine! Thank you very much!

iRon7 commented 4 years ago

Hello Erikov,

I have uploaded a new version of the Join cmdlet (3.2.0) which you might like because I have added two new switches for the -On/-Equals comparison: -Strict and -MatchCase.

This means for your used case, you can now do:

$LeftObject | LeftJoin $RightObject -On lun-serial -MatchCase

(Which will be faster then using expressions).

Note: In this version, I have stricter defined the parameter sets, this means that the -On <ScriptBlock> is actually changed to" -OnExpression <ScriptBlock> but you can still use -On <ScriptBlock> as this -On is an abbreviation of -OnExpression which is only excepting a [ScriptBlock] type.