The reason you don't get an error is probably that the call succeeded!
When you call CreateTextFile
and pass the file path C:\temp:AAAAA.txt
, you're actually asking to create a file C:\temp
with an alternate data stream (an ADS
) named AAAAA.txt
.
You can see for yourself with Get-Item
:
PS C:\> Get-Item C:\temp -Stream AAAAA.txt
PSPath : Microsoft.PowerShell.Core\FileSystem::C:\temp:AAAAA.txt
PSParentPath : Microsoft.PowerShell.Core\FileSystem::C:\
PSChildName : temp:AAAAA.txt
PSDrive : C
PSProvider : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
FileName : C:\temp
Stream : AAAAA.txt
Length : 0
You can also read and write to alternate data streams (requires PowerShell version 5 or newer):
PS C:\> "Hello there!" |Set-Content C:\temp -Stream AAAAA.txt
PS C:\> Get-Content C:\temp -Stream AAAAA.txt
Hello there!
Please beware that these data streams are intrinsic to NTFS and won't persist if you copy a file to a non-NTFS file system or upload them to a website for example.