Search notes:

PowerShell: set Zone.Identifier to simulate file being downloaded from the Internet

Some browsers mark a file that was being downloaded from the file by setting this file's alternate data stream Zone.Identifier.
PowerShell relies on this information for example to determine if it should run a script.
The following example uses the PowerShell cmdlet set-content to fill the data stream Zone.Identifier, thus prepending that the file was downloaded from the Internet.
$filepath = "$pwd/simulate-downloaded-file.txt"
$url      = 'https://someUrl.xyz/'

set-content $filepath @'
Prepend that this
file was downloaded
from the internet
'@

set-content $filepath -stream Zone.Identifier @"
[ZoneTransfer]
ZoneId=3
ReferrerUrl=$url
HostUrl=$url$(split-path -leaf $filepath)
"@
Github repository about-PowerShell, path: /cmdlets/content/set/set-stream-Zone.Identifier.ps1
The cmdlet unblock-file removes this stream, which is sometimes required to be able to execute a downloaded Powershell script.

Index