Skip to content

Fixes #12621 - Document behavior of wildcard matching when -Destination doesn't exist#12670

Merged
sdwheeler merged 1 commit intoMicrosoftDocs:mainfrom
sdwheeler:sdw-w545589-i12621-copy
Jan 17, 2026
Merged

Fixes #12621 - Document behavior of wildcard matching when -Destination doesn't exist#12670
sdwheeler merged 1 commit intoMicrosoftDocs:mainfrom
sdwheeler:sdw-w545589-i12621-copy

Conversation

@sdwheeler
Copy link
Copy Markdown
Collaborator

@sdwheeler sdwheeler commented Jan 17, 2026

PR Summary

Document behavior of wildcard matching when -Destination doesn't exist

PR Checklist

  • Descriptive Title: This PR's title is a synopsis of the changes it proposes.
  • Summary: This PR's summary describes the scope and intent of the change.
  • Contributor's Guide: I have read the contributor's guide.
  • Style: This PR adheres to the style guide.

Copilot AI review requested due to automatic review settings January 17, 2026 14:19
@learn-build-service-prod
Copy link
Copy Markdown
Contributor

PoliCheck Scan Report

The following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans.

✅ No issues found

More information about PoliCheck

Information: PoliCheck | Severity Guidance | Term
For any questions: Try searching the learn.microsoft.com contributor guides or post your question in the Learn support channel.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request documents the behavior of Copy-Item when using wildcard matching with a non-existent destination path, addressing issue #12621. The changes include documentation updates and code example improvements across multiple PowerShell versions.

Changes:

  • Added documentation explaining the behavior when the destination doesn't exist with wildcard paths
  • Refactored several code examples to use PowerShell splatting pattern for better readability
  • Updated the ms.date metadata field to reflect the documentation update

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 12 comments.

File Description
reference/7.6/Microsoft.PowerShell.Management/Copy-Item.md Added wildcard behavior documentation, refactored Examples 4, 8, and 11 to use splatting, updated date metadata
reference/7.5/Microsoft.PowerShell.Management/Copy-Item.md Added wildcard behavior documentation note only, updated date metadata
reference/7.4/Microsoft.PowerShell.Management/Copy-Item.md Added wildcard behavior documentation, refactored Examples 4, 8, and 11 to use splatting, updated date metadata
reference/5.1/Microsoft.PowerShell.Management/Copy-Item.md Added wildcard behavior documentation, refactored Examples 4, 8, and 11 to use splatting, updated date metadata

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

>
> `Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse`
>
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar error: "If the C:\Logfiles only contains" should be "If C:\Logfiles only contains" (remove "the" before the path). Paths used as subjects don't require the article "the" in this context.

Suggested change
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't

Copilot uses AI. Check for mistakes.
>
> `Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse`
>
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar error: "If the C:\Logfiles only contains" should be "If C:\Logfiles only contains" (remove "the" before the path). Paths used as subjects don't require the article "the" in this context.

Suggested change
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't

Copilot uses AI. Check for mistakes.
Comment on lines +118 to +120
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> file is a copy of the last file in the `C:\Logfiles` directory.
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states "all files in C:\Logfiles are copied to C:\Drawings\Logs as a file" which is confusing and unclear. The phrase "copied to C:\Drawings\Logs as a file" doesn't make sense because multiple files cannot be copied to a single file path. The statement should clarify that each file except the last is overwritten by the next, resulting in only the last file being preserved, or describe the actual behavior more accurately.

Suggested change
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> file is a copy of the last file in the `C:\Logfiles` directory.
> If `C:\Logfiles` contains only files (no subdirectories) and `C:\Drawings\Logs` doesn't exist,
> each file in `C:\Logfiles` is copied in turn to the same destination path, `C:\Drawings\Logs`,
> so each copy overwrites the previous one. The resulting `C:\Drawings\Logs` file is a copy of
> the last file in the `C:\Logfiles` directory.

Copilot uses AI. Check for mistakes.
>
> `Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse`
>
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar error: "If the C:\Logfiles only contains" should be "If C:\Logfiles only contains" (remove "the" before the path). Paths used as subjects don't require the article "the" in this context.

Suggested change
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't

Copilot uses AI. Check for mistakes.
>
> `Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse`
>
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar error: "If the C:\Logfiles only contains" should be "If C:\Logfiles only contains" (remove "the" before the path). Paths used as subjects don't require the article "the" in this context.

Suggested change
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't

Copilot uses AI. Check for mistakes.
Comment on lines +117 to 120
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> file is a copy of the last file in the `C:\Logfiles` directory.

Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states "all files in C:\Logfiles are copied to C:\Drawings\Logs as a file" which is confusing and unclear. The phrase "copied to C:\Drawings\Logs as a file" doesn't make sense because multiple files cannot be copied to a single file path. The statement should clarify that each file except the last is overwritten by the next, resulting in only the last file being preserved, or describe the actual behavior more accurately.

Suggested change
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> file is a copy of the last file in the `C:\Logfiles` directory.
> If `C:\Logfiles` contains only files and no subdirectories, and `C:\Drawings\Logs` doesn't
> exist, PowerShell treats `C:\Drawings\Logs` as a file path rather than a directory. Each file in
> `C:\Logfiles` is copied in turn to `C:\Drawings\Logs`, overwriting the previous one, so the final
> `C:\Drawings\Logs` file is a copy of the last file in the `C:\Logfiles` directory.

Copilot uses AI. Check for mistakes.
Comment on lines +118 to 121
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> file is a copy of the last file in the `C:\Logfiles` directory.

Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent reference: The sentence refers to "The C:\Drawings file" but previously mentions "C:\Drawings\Logs" as the destination. This creates confusion because C:\Drawings is described as a file rather than a directory. The sentence should clarify that when C:\Drawings\Logs doesn't exist, it's treated as a file path (not a directory), and explain the behavior more clearly.

Suggested change
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> file is a copy of the last file in the `C:\Logfiles` directory.
> If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, the destination path is treated as a file name rather than a directory. A single file
> named `C:\Drawings\Logs` is created, and its contents are a copy of the last file in the
> `C:\Logfiles` directory that is processed.

Copilot uses AI. Check for mistakes.
Comment on lines +117 to +118
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states "all files in C:\Logfiles are copied to C:\Drawings\Logs as a file" which is confusing and unclear. The phrase "copied to C:\Drawings\Logs as a file" doesn't make sense because multiple files cannot be copied to a single file path. The statement should clarify that each file except the last is overwritten by the next, resulting in only the last file being preserved, or describe the actual behavior more accurately.

Suggested change
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> If `C:\Logfiles` contains only files (no subdirectories) and `C:\Drawings\Logs` doesn't
> exist, PowerShell treats `C:\Drawings\Logs` as the path to a single file. Each file from
> `C:\Logfiles` is copied to that same destination path in turn, so the final `C:\Drawings\Logs`

Copilot uses AI. Check for mistakes.
Comment on lines +117 to 120
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> file is a copy of the last file in the `C:\Logfiles` directory.

Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent reference: The sentence refers to "The C:\Drawings file" but previously mentions "C:\Drawings\Logs" as the destination. This creates confusion because C:\Drawings is described as a file rather than a directory. The sentence should clarify that when C:\Drawings\Logs doesn't exist, it's treated as a file path (not a directory), and explain the behavior more clearly.

Suggested change
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> file is a copy of the last file in the `C:\Logfiles` directory.
> If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, `Copy-Item` treats `C:\Drawings\Logs` as a file path, not a directory. Each file from
> `C:\Logfiles` is copied in turn to `C:\Drawings\Logs`, so the `C:\Drawings\Logs` file ends up
> containing the contents of the last file in the `C:\Logfiles` directory.

Copilot uses AI. Check for mistakes.
Comment on lines +117 to +119
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> file is a copy of the last file in the `C:\Logfiles` directory.
Copy link

Copilot AI Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent reference: The sentence refers to "The C:\Drawings file" but previously mentions "C:\Drawings\Logs" as the destination. This creates confusion because C:\Drawings is described as a file rather than a directory. The sentence should clarify that when C:\Drawings\Logs doesn't exist, it's treated as a file path (not a directory), and explain the behavior more clearly.

Suggested change
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
> file is a copy of the last file in the `C:\Logfiles` directory.
> If `C:\Logfiles` contains only files and no subdirectories and `C:\Drawings\Logs` doesn't exist,
> `Copy-Item` treats `C:\Drawings\Logs` as the full path to a file, not a directory. All files in
> `C:\Logfiles` are copied in sequence, and the contents of the last file overwrite the previous
> content. The resulting `C:\Drawings\Logs` file contains the contents of the last file in the
> `C:\Logfiles` directory.

Copilot uses AI. Check for mistakes.
@learn-build-service-prod
Copy link
Copy Markdown
Contributor

Learn Build status updates of commit c62c1d3:

✅ Validation status: passed

File Status Preview URL Details
reference/5.1/Microsoft.PowerShell.Management/Copy-Item.md ✅Succeeded View (powershell-5.1)
reference/7.4/Microsoft.PowerShell.Management/Copy-Item.md ✅Succeeded View (powershell-7.4)
reference/7.5/Microsoft.PowerShell.Management/Copy-Item.md ✅Succeeded View (powershell-7.5)
reference/7.6/Microsoft.PowerShell.Management/Copy-Item.md ✅Succeeded View (powershell-7.6)

For more details, please refer to the build report.

@sdwheeler sdwheeler merged commit ca6df6b into MicrosoftDocs:main Jan 17, 2026
14 checks passed
@sdwheeler sdwheeler deleted the sdw-w545589-i12621-copy branch January 17, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Document Copy-Item's behavior when wildcard matching is performed and -Destination doesn't exist

2 participants