Private/Get-VesterChildItem.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
# Modified Get-ChildItem for Vester purposes
# Handles the different logic paths allowed by Get-VesterTest

function Get-VesterChildItem {
    [CmdletBinding()]
    param (
        $Path,
        $Scope,
        $Name,
        # Prevent @PSBoundParameters invocation error, but don't do anything
        $Simple
    )

    Write-Verbose "[Get-VesterChildItem] $Path"

    If ($Scope -and $Name) {
        $Name | ForEach-Object {
            Get-ChildItem -Path $Path -Filter "$_.Vester.ps1" -File -Recurse |
                Select-Object @{n='Name';e={($_.BaseName -split '\.')[0]}},
                                @{n='Scope';e={($_.Directory -split '\\')[-1]}},
                                FullName |
                Where-Object Scope -in $Scope
        }
    } ElseIf ($Scope) {
        Get-ChildItem -Path $Path -Filter '*.Vester.ps1' -File -Recurse |
            Select-Object @{n='Name';e={($_.BaseName -split '\.')[0]}},
                            @{n='Scope';e={($_.Directory -split '\\')[-1]}},
                            FullName |
            Where-Object Scope -in $Scope
    } ElseIf ($Name) {
        $Name | ForEach-Object {
            Get-ChildItem -Path $Path -Filter "$_.Vester.ps1" -File -Recurse |
                Select-Object @{n='Name';e={($_.BaseName -split '\.')[0]}},
                                @{n='Scope';e={($_.Directory -split '\\')[-1]}},
                                FullName
        }
    } Else {
        Get-ChildItem -Path $Path -Filter '*.Vester.ps1' -File -Recurse |
            Select-Object @{n='Name';e={($_.BaseName -split '\.')[0]}},
                            @{n='Scope';e={($_.Directory -split '\\')[-1]}},
                            FullName
    }
}