-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-SubFiles.ps1
83 lines (66 loc) · 1.77 KB
/
Get-SubFiles.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
function Get-SubFiles {
[CmdletBinding(DefaultParameterSetName = 'OnlyName')]
param (
[string]
[Parameter(ValueFromPipeline)]
$Path = (Get-Location),
[switch]
[Alias('All')]
$Recurse,
[uint16]
$Depth,
[string[]]
$Exclude,
[string[]]
$Include,
[string]
$Filter,
[switch]
[Parameter(ParameterSetName = 'OnlyFull',
Mandatory)]
[Alias('Full')]
$FullName,
[switch]
[Parameter(ParameterSetName = 'Both',
Mandatory)]
$Both
)
process {
$Item = Get-Item -LiteralPath (Get-FolderFullName $Path)
$Prms = @{
LiteralPath = $Item.FullName
File = $true
}
$Keys = (
'Recurse',
'Depth',
'Exclude',
'Include',
'Filter'
)
foreach ($Key in $Keys) {
if ($Key -in $PSBoundParameters.Keys) {
$Prms[$Key] = (Get-Variable $Key).Value
}
}
$SelectProps, $SortProp = switch ($PSCmdlet.ParameterSetName) {
'Both' {
('Name', 'FullName'),
'FullName'
}
'OnlyName' {
'Name',
'Name'
}
'OnlyFull' {
'FullName',
'FullName'
}
}
$SubFiles = Get-ChildItem @Prms | Select-Object -Property $SelectProps | Sort-Object -Property $SortProp
$SubFiles
} # End process block
} # End function
('F') | ForEach-Object {
Set-Alias -Name $_ -Value Get-SubFiles
}