Skip to content

Commit 7eb49f2

Browse files
Merge branch 'Search-PSMDPropertyValue' into development
2 parents 75790ba + 4c148ed commit 7eb49f2

File tree

11 files changed

+328
-2
lines changed

11 files changed

+328
-2
lines changed

PSModuleDevelopment/PSModuleDevelopment.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
'Remove-PSMDTemplate',
8787
'Rename-PSMDParameter',
8888
'Restart-PSMDShell',
89+
'Search-PSMDPropertyValue',
8990
'Set-PSMDEncoding',
9091
'Set-PSMDModuleDebug',
9192
'Set-PSMDCmdletBinding',
512 Bytes
Binary file not shown.
Binary file not shown.

PSModuleDevelopment/bin/PSModuleDevelopment.xml

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PSModuleDevelopment/changelog.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# Changelog
2+
##
3+
- New: Format-PSMDParameter - updates legacy parameter notation
4+
- New: Search-PSMDPropertyValue - search objects for values in properties
5+
- Fix: New-PSMDTemplate records binary files as text files
6+
27
## 2.2.5.41 (December 18th, 2018)
38
- Fix: Get-PSMDMember - dropping the unintentional bool return
49

510
## 2.2.5.40 (December 17th, 2018)
611
- New: Command Show-PSMDSyntax, used to show the parameter syntax with proper highlighting
712
- New: Command Get-PSMDMember, used to show the members in a more organic and useful way
813
- Fix: Template PSFProject build step was broken
9-
10-
## 2.2.5.37 (October 20th, 2018)
14+
15+
## 2.2.5.37 ( October 20th, 2018)
1116
- Upd: Set-PSMDModulePath - add `-Module` parameter to persist the setting
1217
- Upd: Set-PSMDModulePath - add `-Register` parameter for integrated persistence
1318
- Upd: Set-PSMDEncoding - use `PSFEncoding` parameter class & tabcompletion

PSModuleDevelopment/functions/templating/New-PSMDTemplate.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@
505505
{
506506
$bytes = [System.IO.File]::ReadAllBytes($Item.FullName)
507507
$object.Value = [System.Convert]::ToBase64String($bytes)
508+
$object.PlainText = $false
508509
}
509510
#endregion File Content
510511
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
function Search-PSMDPropertyValue
2+
{
3+
<#
4+
.SYNOPSIS
5+
Recursively search an object for property values.
6+
7+
.DESCRIPTION
8+
Recursively search an object for property values.
9+
This can be useful to determine just where an object stores a given piece of information in scenarios, where objects either have way too many properties or a deeply nested data structure.
10+
11+
.PARAMETER Object
12+
The object to search.
13+
14+
.PARAMETER Value
15+
The value to search for.
16+
17+
.PARAMETER Match
18+
Search by comparing with regex, rather than equality comparison.
19+
20+
.PARAMETER Depth
21+
Default: 3
22+
How deep should the query recurse.
23+
The deeper, the longer it can take on deeply nested objects.
24+
25+
.EXAMPLE
26+
PS C:\> Get-Mailbox Max.Mustermann | Search-PSMDPropertyValue -Object '[email protected]' -Match
27+
28+
Searches all properties on the mailbox of Max Mustermann for his email address.
29+
#>
30+
[CmdletBinding()]
31+
param (
32+
[AllowNull()]
33+
$Value,
34+
35+
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
36+
$Object,
37+
38+
[switch]
39+
$Match,
40+
41+
[int]
42+
$Depth = 3
43+
)
44+
45+
begin
46+
{
47+
function Search-Value
48+
{
49+
[CmdletBinding()]
50+
param (
51+
$Object,
52+
53+
$Value,
54+
55+
[bool]
56+
$Match,
57+
58+
[int]
59+
$Depth,
60+
61+
[string[]]
62+
$Elements,
63+
64+
$InputObject
65+
)
66+
67+
$path = $Elements -join "."
68+
Write-PSFMessage -Level Verbose -Message "Processing $path"
69+
70+
foreach ($property in $Object.PSObject.Properties)
71+
{
72+
if ($path) { $tempPath = $path, $property.Name -join "." }
73+
else { $tempPath = $property.Name }
74+
if ($Match)
75+
{
76+
if ($property.Value -match $Value)
77+
{
78+
New-Object PSModuleDevelopment.Utility.PropertySearchResult($property.Name, $Elements, $property.Value, $InputObject)
79+
}
80+
}
81+
else
82+
{
83+
if ($Value -eq $property.Value)
84+
{
85+
New-Object PSModuleDevelopment.Utility.PropertySearchResult($property.Name, $Elements, $property.Value, $InputObject)
86+
}
87+
}
88+
89+
if ($Elements.Count -lt $Depth)
90+
{
91+
$newItems = New-Object System.Object[]($Elements.Count)
92+
$Elements.CopyTo($newItems, 0)
93+
$newItems += $property.Name
94+
Search-Value -Object $property.Value -Value $Value -Match $Match -Depth $Depth -Elements $newItems -InputObject $InputObject
95+
}
96+
}
97+
}
98+
}
99+
100+
process
101+
{
102+
Search-Value -Object $Object -Value $Value -Match $Match.ToBool() -Depth $Depth -Elements @() -InputObject $Object
103+
}
104+
}

PSModuleDevelopment/xml/PSModuleDevelopment.Format.ps1xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,40 @@
137137
</TableRowEntries>
138138
</TableControl>
139139
</View>
140+
141+
<!-- PSModuleDevelopment.Utility.PropertySearchResult -->
142+
<View>
143+
<Name>PSModuleDevelopment.Utility.PropertySearchResult</Name>
144+
<ViewSelectedBy>
145+
<TypeName>PSModuleDevelopment.Utility.PropertySearchResult</TypeName>
146+
</ViewSelectedBy>
147+
<TableControl>
148+
<AutoSize/>
149+
<TableHeaders>
150+
<TableColumnHeader/>
151+
<TableColumnHeader/>
152+
<TableColumnHeader/>
153+
<TableColumnHeader/>
154+
</TableHeaders>
155+
<TableRowEntries>
156+
<TableRowEntry>
157+
<TableColumnItems>
158+
<TableColumnItem>
159+
<PropertyName>Path</PropertyName>
160+
</TableColumnItem>
161+
<TableColumnItem>
162+
<PropertyName>Depth</PropertyName>
163+
</TableColumnItem>
164+
<TableColumnItem>
165+
<PropertyName>Name</PropertyName>
166+
</TableColumnItem>
167+
<TableColumnItem>
168+
<PropertyName>Value</PropertyName>
169+
</TableColumnItem>
170+
</TableColumnItems>
171+
</TableRowEntry>
172+
</TableRowEntries>
173+
</TableControl>
174+
</View>
140175
</ViewDefinitions>
141176
</Configuration>

library/PSModuleDevelopment/PSModuleDevelopment/Format/ViewDefinitionBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public abstract class ViewDefinitionBase : IComparable
3737
/// <returns>The format string to produce for the format file.</returns>
3838
public abstract override string ToString();
3939

40+
/// <summary>
41+
/// Implement IComparable
42+
/// </summary>
43+
/// <param name="Item">The item to compare the current instance with</param>
44+
/// <returns>1, 0 or -1</returns>
4045
public int CompareTo(object Item)
4146
{
4247
ViewDefinitionBase tempItem = Item as ViewDefinitionBase;

library/PSModuleDevelopment/PSModuleDevelopment/PSModuleDevelopment.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="Template\TemplateItemFile.cs" />
6363
<Compile Include="Template\TemplateItemFolder.cs" />
6464
<Compile Include="Template\TemplateType.cs" />
65+
<Compile Include="Utility\PropertySearchResult.cs" />
6566
<Compile Include="Utility\TextAlignment.cs" />
6667
<Compile Include="Utility\TextHeader.cs" />
6768
<Compile Include="Utility\UtilityHost.cs" />

0 commit comments

Comments
 (0)