Alternate Data Streams

Home  >>  PowerShell  >>  Alternate Data Streams

Alternate Data Streams

On January 18, 2007, Posted by , In PowerShell,Rant, With 2 Comments

NTFS has the ability to associate multiple data streams (aka forks) to a file. It’s not very well supported in most Microsoft tools and not very well known, but I use them quite a bit for associating metadata with files.

Unfortunately, PowerShell (or rather .NET) doesn’t support them very well.

If I open up a “Command Prompt” window (CMD.EXE), I can do things like this:

CMD>echo Hello world > file.txt

CMD>echo Hello other world > file.txt:other

CMD>more < file.txt
Hello world

CMD>more < file.txt:other
Hello other world

As you can see, file.txt has two streams, the default one and one named other.

Back in PowerShell:

PS>gc file.txt                                                                                                          
Hello world                                                                                                             
PS>gc file.txt:other                                                                                                    
Get-Content : Cannot find drive. A drive with name 'file.txt' does not exist.                                           
At line:1 char:3                                                                                                        
+ gc  < < file.txt:other                                                                                               

PowerShell doesn't like it. It incorrectly parses the part before the colon as a drive. Even if PowerShell did parse it properly, the underlying .NET bit would fail with System.NotSupportedException: The given path's format is not supported..

Perhaps Microsoft don't want people using ADS any more... or perhaps they're just not sure... if you Move-Item or Copy-Item the file, the extra stream is moved/copied intact.

2 Comments so far:

  1. PowerShell : Accessing alternative data-streams of files on an NTFS volume ……

    As Adrian Milliner, mentioned on his blog here : Alternate Data Streams , Alternate Data Streams are…