0

I am still very new to the concept of objects and can't wrap my head around this:

PS C:\Windows\system32> $obj1 = New-Object psobject
$obj1 | Add-Member -NotePropertyName Whatever -NotePropertyValue "blah"

$obj2 = New-Object psobject
$obj2 | Add-Member -NotePropertyName Whatever -NotePropertyValue "blih blah"

$obj2 | %{$obj1 -match $_}
False

Ok so it seems like I can't use the -match operator on a PSCustomObject System.Object apparently..because the string "blah" is present in both objects.

so if I try :

PS C:\Windows\system32> $arr1 = @("blah")
$arr2 = @("blih blah")
$arr1 | %{$arr2 -match $_}
blih blah

Then it works! So what? Do I need to convert any PSCustomObject System.Object into an Object System.Array before I can use operators like "-match" ??

Surely, there must be a quick and straight forward way to do this directly from a PSCustomObject System.Object, no?

All I want to do is parse 2 PSCustomObject System.Object and check if the values of the first one are present in the 2nd one in a way or another (full match, partial match etc..)

Thanks very much!

Bluz
  • 5,980
  • 11
  • 32
  • 40
  • mmm... I just found the solution .. PS C:\Windows\system32> $obj1 = New-Object psobject $obj1 | Add-Member -NotePropertyName Whatever -NotePropertyValue "blah" $obj2 = New-Object psobject $obj2 | Add-Member -NotePropertyName Whatever -NotePropertyValue "blih blah" $obj1 | %{$obj2.Whatever -match $_.Whatever} True Ok I had to specify the properties I wanted to compare..Makes sense. I leave the question open in case if somebody has a trick/suggestion or something up their sleeve that can be handy for future reference :) – Bluz Sep 20 '13 at 10:53

1 Answers1

0
$obj1 = New-Object psobject
$obj1 | Add-Member -NotePropertyName Whatever -NotePropertyValue "blah"

$obj2 = New-Object psobject
$obj2 | Add-Member -NotePropertyName Whatever -NotePropertyValue "blih blah"

$obj1 | %{$obj2.Whatever -match $_.Whatever}
Bluz
  • 5,980
  • 11
  • 32
  • 40