Skip to content

Adding dynamic switch -File to a Get-ChildItem call with -Exclude outputs nothing, if -Path is used #20191

Open

Description

Prerequisites

Steps to reproduce

Note:

# !! 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

Actual behavior

No output.

Error details

No response

Environment data

PowerShell 7.4.0-preview.5

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Aug 31, 2023
  2. 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
  3. TobiasPSP commented on Nov 17, 2023

    @TobiasPSP
    Collaborator

    I think -Exclude requires to also use -Include. Can you try by adding -Include * ?

  4. mklement0 commented on Nov 17, 2023

    @mklement0
    ContributorAuthor

    That doesn't make a difference, and -Include isn'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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-Triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions