PowerShell Core (unlike Windows PowerShell) by default is supposed to not follow symlinks (symbolic links) to directories during recursive traversal with Get-ChildItem -Recurse (you can opt in with -FollowSymlink).
While this generally works, using the -Name or -Include / -Exclude switches unexpectedly causes symlinks to be followed even without the -FollowSymlink switch.
Note: On Windows, the tests currently fail categorically, due to an unrelated bug: #9127
Steps to reproduce (on Unix)
Run the following Pester tests:
Describe "Get-ChildItem: symlink-following tests" {
BeforeAll {
Push-Location TestDrive:/
# Create a directory with 2 files in it.
$null = New-Item -Type Directory someDir
1..2 | % { $_ > "someDir/$_.txt" }
# Create a symlink to that directory, as a sibling.
New-Item -Type SymbolicLink someDirLink -Target someDir
}
AfterAll {
Pop-Location
}
It "Get-ChildItem -Recurse doesn't follow dir. symlinks." {
(Get-ChildItem -File -Recurse).Count | Should -Be 2
}
It "Get-ChildItem -Recurse -Path with a wildcard doesn't follow dir. symlinks." {
(Get-ChildItem -File -Recurse -Path *).Count | Should -Be 2
}
It "Get-ChildItem -Recurse -Name doesn't follow dir. symlinks." {
(Get-ChildItem -File -Recurse -Name).Count | Should -Be 2
}
It "Get-ChildItem -Recurse -Include doesn't follow dir. symlinks." {
(Get-ChildItem -File -Recurse -Include *).Count | Should -Be 2
}
It "Get-ChildItem -Recurse -Exclude doesn't follow dir. symlinks." {
(Get-ChildItem -File -Recurse -Exclude nosuch).Count | Should -Be 2
}
}
Expected behavior
All tests should pass.
Actual behavior
The last 3 tests fail.
Environment data
PowerShell Core 6.2.0-rc.1
PowerShell Core (unlike Windows PowerShell) by default is supposed to not follow symlinks (symbolic links) to directories during recursive traversal with
Get-ChildItem -Recurse(you can opt in with-FollowSymlink).While this generally works, using the
-Nameor-Include/-Excludeswitches unexpectedly causes symlinks to be followed even without the-FollowSymlinkswitch.Note: On Windows, the tests currently fail categorically, due to an unrelated bug: #9127
Steps to reproduce (on Unix)
Run the following Pester tests:
Expected behavior
All tests should pass.
Actual behavior
The last 3 tests fail.
Environment data