Get-ChildItem -Recurse -Path $pathSource | % { if ($_.PSIsContainer) { Write-Output "This is a directory, skip it" } else { Write-Output "Do stuff" } }