Public/Get-ISComponent.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
<#
.SYNOPSIS
    Gets all installed IntelliSearch components
.DESCRIPTION
    The Get-ISComponent cmdlet will list out all installed components, optionally matching the supplied name
.EXAMPLE
    Get-ISComponent -Name "Crawler*"
    This will match all components where the name begins with "Crawler"
.INPUTS
    System.String
.OUTPUTS
    Component
#>

function Get-ISComponent {
    [CmdletBinding(ConfirmImpact='None')]
    [OutputType()]
    param(
        [Parameter(
            Mandatory=$false,
            Position=0,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true
        )]
        [Alias()]
        [String] $Name,

        [Parameter(
            Mandatory=$false,
            Position=1,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true
        )]
        [ValidateScript({ Test-Path $_ -PathType Container -IsValid})]
        [Alias()]
        [String] $InstallDirectory = $IS_Settings.ComponentStore
    )

    begin
    {
        $ComponentDetailRegex = "^(IntelliSearch(?:\.\w+)+)(?:\.)(((?:0|(?:[1-9]\d*)))\.((?:0|(?:[1-9]\d*)))\.((?:0|(?:[1-9]\d*)))(?:-([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?)$"
    }

    process
    {   
        Write-Verbose "InstallDirectory: $($InstallDirectory)"

        if (!(Test-Path $InstallDirectory))
        {
            Return
        }

        $InstallDirectoryContents = Get-ChildItem -Path $InstallDirectory -Directory

        foreach ($ComponentDirectory in $InstallDirectoryContents)
        {   
            Write-Verbose "Current component directory: $($ComponentDirectory.FullName)"
            $ComponentDetails = [Regex]::Match($ComponentDirectory.BaseName, $ComponentDetailRegex)
            if ($ComponentDetails.Success -eq $false)
            {
                Write-Verbose "Skipping directory $($ComponentDirectory.FullName) as directory name is not valid"
                continue
            }

            if ($Name -and $ComponentDetails.Value -notlike $Name)
            {
                Write-Verbose "Skipping directory $($ComponentDirectory.FullName) as directory name does not match -Name"
                continue
            }

            $ComponentNupkg = Get-ChildItem -Path $ComponentDirectory.FullName -Recurse | Where-Object {$_.Extension -eq ".nupkg"}
            Write-Verbose "Nupkg count: $($ComponentNupkg.Count)"

            if ($ComponentNupkg.Count -eq 0)
            {
                Write-Verbose "Skipping directory $($ComponentDirectory.FullName) due to it not having a valid nupkg file"
                continue
            }

            [PSCustomObject]@{
                ComponentName      = $ComponentDetails.Value
                ComponentType      = $ComponentDetails.Groups[1].Value
                ComponentVersion   = $ComponentDetails.Groups[2].Value
                ComponentDirectory = $ComponentDirectory.FullName
            }
        }


    }

    end
    {

    }
}