将字符串匹配到包含具有许多属性的对象的变量中

Match a string into a variable containing an object with many properties

我想问一下在 powershell 中将字符串匹配到包含具有许多属性的对象的变量中的方法。

变量是这样的形式:

$a = object -> property1 -> value1
            ->     "      -> value2
            -> property2 -> value3  

我会将字符串匹配到对象的每个值 1、2、3 等等。

非常感谢。

编辑:

为了帮助你理解我需要这样的东西而不指明 属性

Where-Object -property Property1 -eq "test"

假设您所有的对象属性都是值类型,您可以将对象转换为 CSV,并匹配该字符串:

$object = [PSCustomObject]@{
Property1 = 'Value1'
Property2 = 'Value2'
Property3 = 'Value3'
}

$String = '"Value1","Value2","Value3"'

$string -eq  ($object | ConvertTo-Csv -NoTypeInformation)[1]
True