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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<#
.SYNOPSIS
    Gets all installed IntelliSearch components
.DESCRIPTION
    The Get-ISComponent cmdlet will list out all installed components, optionally matching the supplied name
.EXAMPLE
    C:\PS> Get-ISComponent
 
    ComponentName ComponentVersion
    ------------- ----------------
    IntelliSearch.Client.ENT.Search.ASPNET.6.0.0-Be... 6.0.0-Beta.13
    IntelliSearch.Connector.Dropbox.1.0.0 1.0.0
    IntelliSearch.Connector.Exchange.7.0.7 7.0.7
    IntelliSearch.Connector.File.7.0.12 7.0.12
    IntelliSearch.Connector.File.7.0.8 7.0.8
    IntelliSearch.Connector.GDrive.1.0.0 1.0.0
 
    Lists all installed components on the system.
.EXAMPLE
    C:\PS> Get-ISComponent -Name "IntelliSearch.Server.CrawlerManager*"
 
    ComponentName ComponentVersion
    ------------- ----------------
    IntelliSearch.Server.CrawlerManager.6.0.0-Beta.13 6.0.0-Beta.13
    IntelliSearch.Server.CrawlerManager.6.0.0-Beta.14 6.0.0-Beta.14
 
    Finds the components starting with the supplied name.
.EXAMPLE
    C:\PS> Get-ISComponent -Name "*Connector*"
 
    ComponentName ComponentVersion
    ------------- ----------------
    IntelliSearch.Connector.Dropbox.1.0.0 1.0.0
    IntelliSearch.Connector.Exchange.7.0.7 7.0.7
    IntelliSearch.Connector.File.7.0.12 7.0.12
    IntelliSearch.Connector.File.7.0.8 7.0.8
    IntelliSearch.Connector.GDrive.1.0.0 1.0.0
    IntelliSearch.Connector.Websak.7.1.2-BETA 7.1.2-BETA
 
    This will match all components where the name contains "Connector"
.PARAMETER Name
    The name of the component to search for.
    Accepts wildcards.
.PARAMETER InstallDirectory
    The directory to search for components in.
    Default value from ComponentStore in module settings. Usually C:\Program Files\IntelliSearch
.INPUTS
    System.String
.OUTPUTS
    IntelliSearch.Component.Detail
        An object representing an IntelliSearch 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|Haive)(?:\.\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]@{
                PSTypeName         = "IntelliSearch.Component.Detail"
                ComponentName      = $ComponentDetails.Value
                ComponentType      = $ComponentDetails.Groups[1].Value
                ComponentVersion   = $ComponentDetails.Groups[2].Value
                ComponentDirectory = $ComponentDirectory.FullName
            }
        }


    }

    end
    {

    }
}