-
Notifications
You must be signed in to change notification settings - Fork 60
/
Get-JVItem.ps1
102 lines (85 loc) · 3.58 KB
/
Get-JVItem.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#Requires -PSEdition Core
function Get-JVItem {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 0)]
[String]$Path,
[Parameter()]
[Switch]$Recurse,
[Parameter()]
[Int]$Depth,
[Parameter()]
[Switch]$Strict,
[Parameter()]
[PSObject]$Settings,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('match.minimumfilesize')]
[Int]$MinimumFileSize,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('match.excludedfilestring')]
[Array]$ExcludedStrings,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('match.includedfileextension')]
[Array]$IncludedExtensions,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('match.regex')]
[Boolean]$RegexEnabled,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('match.regex.string')]
[String]$RegexString,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('match.regex.idmatch')]
[Int]$RegexIdMatch,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('match.regex.ptmatch')]
[Int]$RegexPtMatch
)
process {
$fileObject = @()
if ($Settings) {
$MinimumFileSize = $Settings.'match.mninimumfilesize'
$ExcludedStrings = $Settings.'match.excludedfilestring'
$IncludedExtensions = $Settings.'includedfileextension'
$RegexEnabled = $Settings.'match.regex'
$RegexString = $Settings.'match.regex.string'
$RegexIdMatch = $Settings.'match.regex.idmatch'
$RegexPtMatch = $Settings.'match.regex.ptmatch'
}
if ($ExcludedStrings) {
if ($Depth) {
$files = Get-ChildItem -LiteralPath $Path -Recurse:$Recurse -Depth:$Depth -Exclude:$ExcludedStrings | Where-Object {
$_.Extension -in $IncludedExtensions `
-and $_.Length -ge ($FileSize * 1MB)
}
} else {
$files = Get-ChildItem -LiteralPath $Path -Recurse:$Recurse -Exclude:$ExcludedStrings | Where-Object {
$_.Extension -in $IncludedExtensions `
-and $_.Length -ge ($FileSize * 1MB)
}
}
} else {
if ($Depth) {
$files = Get-ChildItem -LiteralPath $Path -Recurse:$Recurse -Depth:$Depth | Where-Object {
$_.Extension -in $IncludedExtensions `
-and $_.Length -ge ($FileSize * 1MB)
}
} else {
$files = Get-ChildItem -LiteralPath $Path -Recurse:$Recurse -Depth:$Depth | Where-Object {
$_.Extension -in $IncludedExtensions `
-and $_.Length -ge ($FileSize * 1MB)
}
}
}
if ($RegexEnabled) {
$files = $files | Where-Object { $_.BaseName -match $RegexString }
foreach ($file in $files) {
$fileObject += $file | Convert-JVTitle -Strict:$Strict -RegexEnabled:$RegexEnabled -RegexString $RegexString -RegexIdMatch $RegexIdMatch -RegexPtMatch $RegexPtMatch
}
} else {
foreach ($file in $files) {
$fileObject += $file | Convert-JVTitle -Strict:$Strict -RegexEnabled:$RegexEnabled
}
}
Write-Output $fileObject
}
}