Skip to content

Commit ad4648f

Browse files
author
Friedrich Weinmann
committed
initial POC
1 parent 2049680 commit ad4648f

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
function Search-PSMDPropertyValue
2+
{
3+
[CmdletBinding()]
4+
param (
5+
$Object,
6+
7+
$Value,
8+
9+
[switch]
10+
$Match,
11+
12+
[int]
13+
$Depth = 3
14+
)
15+
16+
function Search-Value
17+
{
18+
[CmdletBinding()]
19+
param (
20+
$Object,
21+
22+
$Value,
23+
24+
[bool]
25+
$Match,
26+
27+
[int]
28+
$Depth,
29+
30+
[string[]]
31+
$Elements
32+
)
33+
34+
$path = $Elements -join "."
35+
Write-PSFMessage -Level Verbose -Message "Processing $path"
36+
37+
foreach ($property in $Object.PSObject.Properties)
38+
{
39+
if ($path) { $tempPath = $path, $property.Name -join "." }
40+
else { $tempPath = $property.Name }
41+
if ($Match)
42+
{
43+
if ($property.Value -match $Value)
44+
{
45+
[PSCustomObject]@{
46+
Parent = $path
47+
Path = $tempPath
48+
Value = $property.Value
49+
Type = $property.Value.GetType()
50+
Depth = $Elements.Count + 1
51+
}
52+
}
53+
}
54+
else
55+
{
56+
if ($Value -eq $property.Value)
57+
{
58+
[PSCustomObject]@{
59+
Parent = $path
60+
Path = $tempPath
61+
Value = $property.Value
62+
Type = $property.Value.GetType()
63+
Depth = $Elements.Count + 1
64+
}
65+
}
66+
}
67+
68+
if ($Elements.Count -lt $Depth)
69+
{
70+
$newItems = New-Object System.Object[]($Elements.Count)
71+
$Elements.CopyTo($newItems, 0)
72+
$newItems += $property.Name
73+
Search-Value -Object $property.Value -Value $Value -Match $Match -Depth $Depth -Elements $newItems
74+
}
75+
}
76+
}
77+
78+
Search-Value -Object $Object -Value $Value -Match $Match.ToBool() -Depth $Depth -Elements @()
79+
}

0 commit comments

Comments
 (0)