Skip to content

Get-Item -stream now works on directories. (PS #13941) #6648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion reference/7.1/Microsoft.PowerShell.Management/Add-Content.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ Accept wildcard characters: True

### -Stream

This parameter is valid only on Windows.

Specifies an alternative data stream for content. If the stream does not exist, this cmdlet creates
it. Wildcard characters are not supported.

Expand All @@ -418,7 +420,8 @@ data stream. However, we do not recommend this as a way to eliminate security ch
files that are downloaded from the Internet. If you verify that a downloaded file is safe, use the
`Unblock-File` cmdlet.

This parameter was introduced in PowerShell 3.0.
This parameter was introduced in PowerShell 3.0. As of PowerShell 7.2, Add-Content can
target alternative data streams on both files and directories.

```yaml
Type: System.String
Expand Down
11 changes: 10 additions & 1 deletion reference/7.1/Microsoft.PowerShell.Management/Clear-Content.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,26 @@ PS C:\>

### -Stream

This parameter is valid only on Windows.

Specifies an alternative data stream for content.
If the stream does not exist, this cmdlet creates it.
Wildcard characters are not supported.

**Stream** is a dynamic parameter that the **FileSystem** provider adds to `Clear-Content`. This
parameter works only in file system drives.

Stream is a dynamic parameter that the FileSystem provider adds to `Clear-Content`.
This parameter works only in file system drives.
This parameter works only in file system drives,
and will clear the content of alternative data streams on both files and directories.

You can use the `Clear-Content` cmdlet to change the content of the Zone.Identifier alternate data stream.
However, we do not recommend this as a way to eliminate security checks that block files that are downloaded from the Internet.
If you verify that a downloaded file is safe, use the `Unblock-File` cmdlet.

This parameter was introduced in PowerShell 3.0. As of PowerShell 7.2, Clear-Content can set the
content of alternative data streams on both files and directories.

```yaml
Type: System.String
Parameter Sets: (All)
Expand Down
43 changes: 36 additions & 7 deletions reference/7.1/Microsoft.PowerShell.Management/Get-Content.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ faster than retrieving all of the lines and using the `[-1]` index notation.
### Example 5: Get the content of an alternate data stream

This example describes how to use the **Stream** parameter to get the content of an alternate data
stream for files stored on a Windows NTFS volume. In this example, the `Set-Content` cmdlet is used
stream for files and directories stored on a Windows NTFS volume.
In this example, the `Set-Content` cmdlet is used
to create sample content in a file named `Stream.txt`.

```powershell
Expand All @@ -147,8 +148,30 @@ Length : 44
```

```powershell
# Retrieve the content of the primary, or $DATA stream.
Get-Content -Path .\Stream.txt -Stream $DATA
# Retrieve the content of the primary stream. Note the singlequotes to prevent variable substitution.
Get-Content -Path .\Stream.txt -Stream ':$DATA'
```

```Output
This is the content of the Stream.txt file
```

```powershell
# Alternative way to get the same content.
Get-Content -Path .\Stream.txt -Stream ""
# The primary stream doesn't need to be specified to get the primary stream of the file.
# This gets the same data as the prior two examples.
Get-Content -Path .\Stream.txt
```

```Output
This is the content of the Stream.txt file
```

```powershell
# The primary stream doesn't need to be specified to get the primary stream of the file.
# This gets the same data as the prior two examples.
Get-Content -Path .\Stream.txt
```

```Output
Expand Down Expand Up @@ -195,8 +218,10 @@ Added a stream named NewStream to Stream.txt

The **Stream** parameter is a dynamic parameter of the
[FileSystem provider](../microsoft.powershell.core/about/about_filesystem_provider.md#stream-systemstring).
By default `Get-Content` only retrieves data from the primary, or `$DATA` stream. **Streams** can be
By default `Get-Content` only retrieves data from the default, or `':$DATA'` stream. **Streams** can be
used to store hidden data such as attributes, security settings, or other data.
They can also be stored on directories without being child items. Directories cannot and do not
have default data streams.

### Example 6: Get raw content

Expand Down Expand Up @@ -576,12 +601,16 @@ Accept wildcard characters: False

### -Stream

Gets the contents of the specified alternate NTFS file stream from the file. Enter the stream name.
This parameter is valid only on Windows.

Gets the contents of the specified alternative data stream from the file. Enter the stream name.
Wildcards are not supported.

**Stream** is a dynamic parameter that the **FileSystem** provider adds to the `Get-Content` cmdlet.
This parameter works only in file system drives on Windows systems. This parameter was introduced in
Windows PowerShell 3.0.
This parameter works only in file system drives on Windows systems.

This parameter was introduced in Windows PowerShell 3.0. In PowerShell 7.2, Get-Content can
retrieve the content of alternative data streams on both files and directories.

```yaml
Type: System.String
Expand Down
10 changes: 8 additions & 2 deletions reference/7.1/Microsoft.PowerShell.Management/Get-Item.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,18 @@ The new properties that are now part of the output are:

### -Stream

Gets the specified alternate NTFS file stream from the file. Enter the stream name. Wildcards are
supported. To get all streams, use an asterisk (`*`). This parameter isn't valid on folders.
This parameter is valid only on Windows.

Gets the specified alternative data stream from the file. Enter the stream name. Wildcards are
supported. To get all streams, use an asterisk (`*`).
This parameter is valid on directories, but note that directories do not have data streams by default.

**Stream** is a dynamic parameter that the **FileSystem** provider adds to the `Get-Item` cmdlet.
This parameter works only in file system drives.

This parameter was introduced in PowerShell 3.0. As of PowerShell 7.2, Get-Item can get
alternative data streams from both files and directories.

```yaml
Type: System.String[]
Parameter Sets: (All)
Expand Down
5 changes: 4 additions & 1 deletion reference/7.1/Microsoft.PowerShell.Management/Remove-Item.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,17 @@ Accept wildcard characters: False

### -Stream

This parameter is valid only on Windows.

The **Stream** parameter is a dynamic parameter that the FileSystem provider adds to `Remove-Item`.
This parameter works only in file system drives.

You can use `Remove-Item` to delete an alternative data stream. However, it is not the recommended
way to eliminate security checks that block files that are downloaded from the Internet. If you
verify that a downloaded file is safe, use the `Unblock-File` cmdlet.

This parameter was introduced in Windows PowerShell 3.0.
This parameter was introduced in Windows PowerShell 3.0. As of Windows PowerShell 7.2, Remove-Item
can remove alternative data streams from directories as well as files.

```yaml
Type: System.String[]
Expand Down
5 changes: 4 additions & 1 deletion reference/7.1/Microsoft.PowerShell.Management/Set-Content.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ Accept wildcard characters: True

### -Stream

This parameter is valid only on Windows.

Specifies an alternative data stream for content. If the stream does not exist, this cmdlet creates
it. Wildcard characters are not supported.

Expand All @@ -390,7 +392,8 @@ stream. However, we do not recommend this as a way to eliminate security checks
that are downloaded from the Internet. If you verify that a downloaded file is safe, use the
`Unblock-File` cmdlet.

This parameter was introduced in PowerShell 3.0.
This parameter was introduced in PowerShell 3.0. As of PowerShell 7.2, Set-Content can set the
content of alternative data streams on both files and directories.

```yaml
Type: System.String
Expand Down