Skip to content

Commit 39dbbea

Browse files
sassdawev-alje
authored andcommitted
Update about_Foreach.md (#4002)
The last example was not working when the parameter was used and not a pipeline to call the function. Please see the original and the updated version with pester tests here https://github.com/sassdawe/PowerShell/tree/master/from-docs/about_foreach I also added some write-verbose
1 parent f3f4191 commit 39dbbea

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Foreach.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,23 @@ function Get-FunctionPosition {
175175
process {
176176
try {
177177
$filesToProcess = if ($_ -is [System.IO.FileSystemInfo]) {
178+
Write-Verbose "From pipeline"
178179
$_
179180
} else {
180-
$filesToProcess = Get-Item -Path $Path
181+
Write-Verbose "From parameter, $Path"
182+
Get-Item -Path $Path
181183
}
182184
$parser = [System.Management.Automation.Language.Parser]
185+
Write-Verbose "lets start the foreach loop on `$filesToProcess with $($filesToProcess.count) as count"
183186
foreach ($item in $filesToProcess) {
187+
Write-Verbose "$item"
184188
if ($item.PSIsContainer -or
185189
$item.Extension -notin @('.ps1', '.psm1')) {
186190
continue
187191
}
188192
$tokens = $errors = $null
189-
$ast = $parser::ParseFile($item.FullName, ([REF]$tokens),
190-
([REF]$errors))
193+
$parser::ParseFile($item.FullName, ([REF]$tokens),
194+
([REF]$errors)) | Out-Null
191195
if ($errors) {
192196
$msg = "File '{0}' has {1} parser errors." -f $item.FullName,
193197
$errors.Count

0 commit comments

Comments
 (0)