Skip to content

Set-Content -Confirm confirms twice #24434

Open

Description

@iRon7

Prerequisites

Steps to reproduce

Not sure whether this qualify a a bug, but if I use Set-Content -Confirm I need to confirm twice:

  • on the operation "Set Content", and on
  • on the operation "Clear Content" which is in fact an implicit operation

Although, there are several workarounds available, this behavior is quite disturbing when replacing the content of multiple files.

Set-Content -Value 'Foo' -Path .\Temp.txt
Set-Content -Value 'Bar' -Path .\Temp.txt -Confirm

Expected behavior

Confirm
Are you sure you want to perform this action?
Performing the operation "Set Content" on target "Path: .\Temp.txt".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y

Actual behavior

Confirm
Are you sure you want to perform this action?
Performing the operation "Set Content" on target "Path: .\Temp.txt".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y

Confirm
Are you sure you want to perform this action?
Performing the operation "Clear Content" on target "Item: .\Temp.txt".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y

Error details

Note the second

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.5
PSEdition                      Core
GitCommitId                    7.4.5
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Oct 15, 2024
  2. mklement0 commented on Oct 15, 2024

    @mklement0
    Contributor

    Definitely a bug - it seems that (the implementing class behind) Clear-Content is called behind the scenes, which triggers the extra prompt.

    Not only should the Clear-Content prompt not show, if you respond with N, the file is still modified, but the -Value is appended to the existing file (that is, you then get Add-Content behavior).

  3. added
    WG-Cmdlets
    WG-Engine-Providers
    Area-FileSystem-Provider
    WG-NeedsReview
    on Oct 17, 2024
  4. iRon7 commented on Feb 12, 2025

    @iRon7
    Author

    it seems that (the implementing class behind) Clear-Content is called behind the scenes

    Yes, this appears also from invoking Set-Content on a directory:

    Set-Content .\Test '' # where .\Test is a directory
    Set-Content: Unable to clear content of '.\Test' because it is a directory. Clear-Content is only supported on files.
  5. rkeithhill commented on Sep 8, 2025

    @rkeithhill
    Collaborator

    WG-Engine reviewed this and agree this is a bug that should be investigated and fixed.

  6. added
    Up-for-Grabs
    WG-Reviewed
    and removed
    Needs-Triage
    WG-NeedsReview
    on Sep 8, 2025
  7. added
    Issue-Bug
    on Sep 9, 2025
  8. added 2 commits that reference this issue on Dec 1, 2025
    34d926f
    092acf6
  9. added
    Resolution-No Activity
    on Mar 8, 2026
  10. iRon7 commented on Mar 8, 2026

    @iRon7
    Author

    It is still unclear to me why issues marked as Up-for-Grabs are triggered to be closed...

  11. removed
    Resolution-No Activity
    on Mar 8, 2026
  12. doctordns commented on Mar 8, 2026

    @doctordns
    Collaborator

    My view is that this should NOT be the case. That said, something open for grabs that is not grabbed is not a great state to be in either.

    Trigging after a week is wrong, I think we';d agree./ But after 6 months?: After a Year? If no one has taken up the opportunity, after a time, I'm not sure how much sense it makes to leave it open.

  13. added
    Resolution-No Activity
    on Sep 5, 2026
  14. microsoft-github-policy-service commented on Sep 5, 2026

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

  15. mklement0 commented on Sep 5, 2026

    @mklement0
    Contributor

    I'm not sure how much sense it makes to leave it open.

    Echoing iRon7's sentiment in different words: The sensible approach is to leave Up-for-Grabs issues open indefinitely, so that community members - at whatever point in the future - can discover them, know that they've been green-lit for implementation, and therefore potentially submit PRs that may eventually provide a fix.

    The usefulness of an approved fix / improvement has no expiration date.

  16. removed
    Resolution-No Activity
    on Sep 5, 2026
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

    Area-FileSystem-ProviderIssue-BugUp-for-GrabsWG-CmdletsWG-Engine-ProvidersWG-Reviewed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions