-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-Stream.ps1
65 lines (61 loc) · 2.84 KB
/
Get-Stream.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function Get-Stream {
<#
.SYNOPSIS
This function has the capability to find,add and remove Alternate Data Streams from files on a system.
.PARAMETER FilePath
The local or UNC folder path that you'd like to view streams at. Doesn't have to end in a file format it has the ability to just search the folder in general
.PARAMETER $Content
The Data you want to add to a file or a newly created stream.
.PARAMETER StreamName
The Name of the stream you are looking to view or add depending on which parameter set you use.
.PARAMETER Remove
Switch Parameter to Remove ADS from chosen file/files.
.PARAMETER AddStream
Adds a stream to a chosen file/files.
.PARAMETER View
Views Chosen Stream's Data
.PARAMETER Unique
Switch Parameter to Unique on ADS names within files on the system
.EXAMPLE
Get-Stream -Filepath "YourFilePath"
.EXAMPLE Content,AddStream,StreamName
Get-Stream -FilePath "YourFilePath" -StreamName "MyStream" -Content "Hello" -AddStream
.EXAMPLE View
Get-Stream -StreamName "StreamName" -FilePath "Filepath" -View
.EXAMPLE Unique
Get-Stream -FilePath "YourFilePath" -Unique
.INPUTS
This function does not accept pipeline input.
.OUTPUTS
None but can be piped to export files.
#>
[CmdletBinding(DefaultParameterSetName="Set1")]
param(
[Parameter(Mandatory=$true, ParameterSetName="Set1")][Parameter(ParameterSetName="Set2")][string]$Filepath,
[Parameter(Mandatory=$false,ParameterSetName="Set2")][string]$Content,
[Parameter(Mandatory=$false,ParameterSetName="Set2")][string]$StreamName,
[Parameter(Mandatory=$false,ParameterSetName="Set2")][switch]$Remove,
[Parameter(Mandatory=$false,ParameterSetName="Set2")][switch]$AddStream,
[Parameter(Mandatory=$false,ParameterSetName="Set2")][switch]$View,
[Parameter(Mandatory=$false,ParameterSetName="Set1")][switch]$Unique
)
if ($FilePath -and !$Unique -and !$Content -and !$StreamName -and !$Remove -and !$AddStream -and !$View){
Get-ChildItem -Path $Filepath -Recurse *.* | ForEach-Object { Get-Item -Path $_.FullName | Get-Item -Stream * } | Select Filename,Stream
}
if($Remove){
Remove-Item -Path $FilePath -Stream $StreamName
}
if($View){
Get-Content -Stream $StreamName -Path $Filepath
}
if($AddStream){
Add-Content -Stream $StreamName -Value $Content -Path $Filepath
}
if($Unique){
$var=(Get-ChildItem -Path $FilePath -Recurse *.* | ForEach-Object { Get-Item -Path $_.FullName | Get-Item -Stream * } | Where-Object { $_.Stream -ne ':$DATA' -and $_.Stream -ne "Zone.Identifier"}).Stream;
$var2=(Get-ChildItem -Path $FilePath -Recurse *.* | ForEach-Object { Get-Item -Path $_.FullName | Get-Item -Stream * } | Where-Object { $_.Stream -ne ':$DATA' -and $_.Stream -ne "Zone.Identifier"}).FileName;
write-host "These are your Unique Stream names:" ;
write-host $var2 -ForegroundColor red ;
write-host $var -ForegroundColor red
}
}