Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell compare 2 arrays with different properties

i have 2 arrays. Both have a property for the file size, but the property name in the first array is "SizeInByte" and in the other array it is called "Length". Is is possible to use compare-object to compare the two arrays based on the file size ? So far i haven`t found a way to do this :(

like image 629
TrexX Avatar asked Jan 24 '26 15:01

TrexX


1 Answers

Pipe one array to the Add-Member cmdlet and create a SizeInByte alias property for the Length property, then compare the two arrays by the same property name.

$LengthArr = $LengthArr | Add-Member -MemberType AliasProperty -Name SizeInByte -Value Length -PassThru
Compare-Object $LengthArr $SizeInByteArr -Property SizeInByte
like image 99
Shay Levy Avatar answered Jan 26 '26 22:01

Shay Levy