Skip to content

Feature Request: Add parameter to Copy-Item/Move-Item to preserve folder structure #26161

Open

Description

@SetTrend

Summary of the new feature / enhancement

As a user, I'd like to be able to recursively copy items that are satisfying a condition other than a name wildcard.

For example, I'd like to recursively copy log files from a folder structure that have been created in the past month to a new folder while keeping the folder structure.

Proposed technical implementation details (optional)

Modify the Filter parameter to accept a script block argument to Copy-Item, Move-Item, Get-ChildItem etc.

Copy-Item -Path '.\logs\' -Destination '.\export\' -Recurse -Filter{ $_.LastWriteTime -gt [System.DateTime]::Today.AddDays(-30) }

Activity

  1. added
    Issue-Enhancement
    Needs-Triage
    on Oct 8, 2025
  2. changed the title [-]Feature Request: Add predicate function type to `Copy-Item` to filter items[/-] [+]Feature Request: Add predicate script block parameter to `Copy-Item`, `Move-Item`, `Get-ChildItem` for filtering items[/+] on Oct 8, 2025
  3. 237dmitry commented on Oct 8, 2025

    @237dmitry

    It would be nice to expand the Filter parameter for the script block. But there are other well-proven and familiar tools, such as filter and *-Object cmdlets

  4. SetTrend commented on Oct 8, 2025

    @SetTrend
    Author

    Hi 237dmitry, thank you for this valuable information. Would you mind adding hyperlinks to your comment pointing to some of the Cmdlets you feel are relevant?

  5. cauamachado51 commented on Nov 2, 2025

    @cauamachado51

    é parecido com o que queria para Copy-Item: para filtrar -Recurse, algum parâmetro -Only String[] que pode ter:

    • New: copia apenas itens mais novos da origem (em relação ao destino)
    • Old: copia apenas itens mais antigos da origem (em relação ao destino)
    • Big: copia apenas itens mais grandes da origem (em relação ao destino)
    • Small: copia apenas itens mais pequenos da origem (em relação ao destino)
    • Different: copia itens de diferente data ou tamanho (em relação ao destino)
  6. added
    WG-NeedsReview
    WG-Engine
    on Nov 4, 2025
  7. SeeminglyScience commented on Jul 13, 2026

    @SeeminglyScience
    Contributor

    The Engine WG discussed this today, the -Filter parameter is meant to be something that can be passed to the provider implementation in order to improve performance in a way that only the implementation is able to. Generally speaking we would also prefer to keep filtering via scriptblock as something done via Where-Object.

    That said, we believe the ask of preserving folder structure with Copy-Item/Move-Item is worth pursuing. We would accept a dynamic parameter for the FileSystemProvider surfaced in Copy-Item and Move-Item, that specifies the base path to preserve structure from. This would allow piping objects from Get-ChildItem, filtering, and then passing to the copy/move commands.

    # New parameter name undetermined
    Get-ChildItem ./logs -File -Recurse
        | ? LastWriteTime -gt ([System.DateTime]::Today.AddDays(-30))
        | Copy-Item -PreservePathFrom ./logs -Destination ./export
  8. added
    Up-for-Grabs
    and removed
    Needs-Triage
    on Jul 13, 2026
  9. changed the title [-]Feature Request: Add predicate script block parameter to `Copy-Item`, `Move-Item`, `Get-ChildItem` for filtering items[/-] [+]Feature Request: Add parameter to `Copy-Item`/`Move-Item` to preserve folder structure[/+] on Jul 13, 2026
  10. added
    WG-Reviewed
    and removed
    WG-NeedsReview
    on Jul 13, 2026
  11. soroshsabz commented on Nov 20, 2026

    @soroshsabz

    ITNOA

    @microsoft-github-policy-service In-PR label

    /microsoft-github-policy-service add In-PR label

  12. soroshsabz commented on Nov 20, 2026

    @soroshsabz
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

    Issue-EnhancementUp-for-GrabsWG-EngineWG-Reviewed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions