Public/Get-ISComponent.ps1

<#
.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(?:\.\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
    {

    }
}