You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding dynamic switch -File to a Get-ChildItem call with -Exclude outputs nothing, if -Path is used #20191
Adding -Recurse (which obviously changes the semantics) makes the problem go away.
# !! Due to the presence of -File and use of -Path, there is NO OUTPUT.# !! Replacing -Path with -LiteralPath makes the command work as intended.Get-ChildItem-Path C:\Windows -Exclude win.ini -File
Expected behavior
All files (but not directories) in C:\Windows should be reported, with the exception of win.ini
changed the title [-]Adding dynamic switch `-File` to a `Get-ChildItem` call with `-Exclude` outputs nothing[/-][+]Adding dynamic switch `-File` to a `Get-ChildItem` call with `-Exclude` outputs nothing, if `-Path` is used[/+]on Sep 6, 2023
That doesn't make a difference, and -Includeisn't required in combination with -Exclude - you'll see that if you remove -File from the command in the initial post it works as intended (albeit also including excluded directories).
Activity
[-]Adding dynamic switch `-File` to a `Get-ChildItem` call with `-Exclude` outputs nothing[/-][+]Adding dynamic switch `-File` to a `Get-ChildItem` call with `-Exclude` outputs nothing, if `-Path` is used[/+]TobiasPSP commentedon Nov 17, 2023
I think -Exclude requires to also use -Include. Can you try by adding -Include * ?
mklement0 commentedon Nov 17, 2023
That doesn't make a difference, and
-Includeisn't required in combination with-Exclude- you'll see that if you remove-Filefrom the command in the initial post it works as intended (albeit also including excluded directories).mklement0 commentedon Nov 22, 2026
The root cause is likely the same as in: