Skip to content

Commit 13917d4

Browse files
author
James Brundage
committed
Updating Search-PipeScript (adding -Recurse) (#115)
1 parent b9ab293 commit 13917d4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Search-PipeScript.ps1.ps1

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ function Search-PipeScript
4040
[Parameter(ValueFromPipelineByPropertyName)]
4141
[Alias('RegEx')]
4242
[ValidateTypes(TypeName={[string], [Regex], [string[]], [regex[]]})]
43-
$RegularExpression
43+
$RegularExpression,
44+
45+
# If set, will search nested script blocks.
46+
[Alias('SearchNestedScriptBlock')]
47+
[switch]
48+
$Recurse
4449
)
4550

4651
process {
@@ -135,13 +140,16 @@ function Search-PipeScript
135140
[ScriptBlock]::Create('param($ast) $ast.GetType().Name -like "*' + $astType +'*"')
136141
}
137142

143+
# Add this condition to the list of conditions.
138144
$AstCondition += $condition
139145
}
140146
}
141147

148+
# If we have any AST conditions
142149
if ($AstCondition) {
143150
foreach ($condition in $AstCondition) {
144-
$ScriptBlock.Ast.FindAll($condition, $true) |
151+
# Find all of the results.
152+
$ScriptBlock.Ast.FindAll($condition, ($Recurse -as [bool])) |
145153
.InputObject = $inputObject .Result {
146154
$_
147155
} .Expression = $condition .ScriptBlock {

0 commit comments

Comments
 (0)