Skip to content

Commit cee342a

Browse files
StartAutomatingStartAutomating
authored andcommitted
Updating Search-PipeScript (adding -Recurse) (#115)
1 parent 13917d4 commit cee342a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Search-PipeScript.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ function Search-PipeScript {
7979
return $true
8080
})]
8181

82-
$RegularExpression
82+
$RegularExpression,
83+
# If set, will search nested script blocks.
84+
[Alias('SearchNestedScriptBlock')]
85+
[switch]
86+
$Recurse
8387
)
8488
process {
8589
$ScriptBlock = $null
@@ -167,12 +171,15 @@ function Search-PipeScript {
167171
[ScriptBlock]::Create('param($ast) $ast.GetType().Name -like "*' + $astType +'*"')
168172
}
169173

174+
# Add this condition to the list of conditions.
170175
$AstCondition += $condition
171176
}
172177
}
178+
# If we have any AST conditions
173179
if ($AstCondition) {
174180
foreach ($condition in $AstCondition) {
175-
$ScriptBlock.Ast.FindAll($condition, $true) |
181+
# Find all of the results.
182+
$ScriptBlock.Ast.FindAll($condition, ($Recurse -as [bool])) |
176183
& { process {
177184
$in = $this = $_
178185
[PSCustomObject][Ordered]@{

0 commit comments

Comments
 (0)