Skip to content

Get-Content, Set-Content, and Clear-Content should work with datastreams set on directories #13656

@kyanha

Description

@kyanha

Summary of the new feature/enhancement

Set-Content, Clear-Content, and Get-Content should, but currently do not, work on datastreams set on directories.

Bug #10570 requested that Get-Item name -Stream streamname should work the same way for directories that it does for files. Previously, there existed a check that bypassed any datastreams being looked for on directories, but NTFS supports it. PR #13650 allows for this operation.

During the process of writing the tests for #13650, I found that Set-Content would not set a stream on a directory (because Clear-Content does not work on directories). As such, I had to call out to cmd.exe to do so, but the interaction between PowerShell and cmd led to the string it was set to to be followed by two newlines, and I had to change the size test accordingly.

If it's possible to read datastreams on directories, it should be possible to write them.

Proposed technical implementation details (optional)

Get-Content for datastreams on directories should not return an error that the user should use Get-ChildItem instead.
Set-Content for datastreams on directories should behave the same way that it does for datastreams on files. Because Set-Content calls Clear-Content, Clear-Content needs to be changed to look for a -Stream parameter and bypass the directory check if that parameter is provided. Set-Content may also have additional directory checks which would need to be bypassed if a -Stream parameter were provided, but I have not investigated that far.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions