Skip to content

Commit

Permalink
Update about_Foreach.md (#4002)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sassdawe authored and sdwheeler committed Mar 18, 2019
1 parent cd7978b commit fb5950f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions reference/5.1/Microsoft.PowerShell.Core/About/about_Foreach.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,23 @@ function Get-FunctionPosition {
process {
try {
$filesToProcess = if ($_ -is [System.IO.FileSystemInfo]) {
Write-Verbose "From pipeline"
$_
} else {
$filesToProcess = Get-Item -Path $Path
Write-Verbose "From parameter, $Path"
Get-Item -Path $Path
}
$parser = [System.Management.Automation.Language.Parser]
Write-Verbose "lets start the foreach loop on `$filesToProcess with $($filesToProcess.count) as count"
foreach ($item in $filesToProcess) {
Write-Verbose "$item"
if ($item.PSIsContainer -or
$item.Extension -notin @('.ps1', '.psm1')) {
continue
}
$tokens = $errors = $null
$ast = $parser::ParseFile($item.FullName, ([REF]$tokens),
([REF]$errors))
$parser::ParseFile($item.FullName, ([REF]$tokens),
([REF]$errors)) | Out-Null
if ($errors) {
$msg = "File '{0}' has {1} parser errors." -f $item.FullName,
$errors.Count
Expand Down

0 comments on commit fb5950f

Please sign in to comment.