Public/New-ISCrawler.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#requires -version 4

function ModuleRoot { $MyInvocation.ScriptName | Split-Path -Parent}
$DllPath = $(Join-Path $(ModuleRoot | Split-Path -Parent) "\Lib\IntelliSearch.dll")
Add-Type -Path $DllPath

# Scriptblock for ToXml() method of IntelliSearch.CrawlerConfiguration object.
$ToXmlScriptblock = {
    [Xml] $Template = Get-Content -Path ("$PSScriptRoot\CrawlerTemplates\$($This.ConnectorType).template.xml")
    
    $Template.Crawler.InstanceId = $This.InstanceId
    $Template.Crawler.CustomConfiguration.ICDCrawlerConfiguration.Queues.Queue.address = $This.Address
    $Template.Crawler.CustomConfiguration.ICDCrawlerConfiguration.Queues.Queue.setIdentifier = $This.InstanceId

    # If the object instance was created from an XML file, replace a few fields. Otherwise uses the ones in the template.
    if ($This.Type -eq "XmlFile") {
        $Template.Crawler.CustomConfiguration.ICDCrawlerConfiguration.Fields = $This.Fields
        $Template.Crawler.CustomConfiguration.ICDCrawlerConfiguration.DataRecordProcessing = $This.DataRecordProcessing
    }
    
    return [Xml] $Template
}

<#
.SYNOPSIS
    Creates a new crawler object
.DESCRIPTION
    The New-ISCrawler cmdlet creates a new crawler object for use in the other cmdlets in the ISPS module. The object can be inserted into the configuration files via the Add-ICDCrawlerToConfig cmdlet. See the help file of that cmdlet for instructions on how to do so.
.EXAMPLE
    New-ISCrawler MailConnector Exchange
.EXAMPLE
    New-ISCrawler FileConnector FileShare fileserver.domain.com 1337
.INPUTS
    Xml, String, int, int16
.OUTPUTS
    IntelliSearch.CrawlerConfiguration
#>

function New-ISCrawler {
    [CmdletBinding(DefaultParameterSetName='2Param',
                   PositionalBinding=$false,
                   ConfirmImpact='None')]
    [Alias()]
    [OutputType([IntelliSearch.CrawlerConfiguration])]
    Param (
        # XML input for internal module use
        [Parameter(Mandatory=$true,
                Position=0,
                ValueFromPipeline=$true,
                ValueFromPipelineByPropertyName=$true,
                ParameterSetName='xml')]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [Alias()] 
        $XmlInput,

        # The type of connector the object represents
        [Parameter(Mandatory=$true,
                    Position=0,
                    ValueFromPipeline=$true,
                    ValueFromPipelineByPropertyName=$true,
                    ParameterSetName='2Param')]
        [Parameter(Mandatory=$true,
                    Position=0,
                    ValueFromPipeline=$true,
                    ValueFromPipelineByPropertyName=$true,
                    ParameterSetName='4Param')]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [ValidateSet("FileConnector", "MailConnector", "NoType")]
        [Alias()] 
        [String] $Type,
        
        # The instance ID of the connector
        [Parameter(Mandatory=$true,
                    Position=1,
                    ValueFromPipeline=$true,
                    ValueFromPipelineByPropertyName=$true,
                    ParameterSetName='2Param')]
        [Parameter(Mandatory=$true,
                    Position=1,
                    ValueFromPipeline=$true,
                    ValueFromPipelineByPropertyName=$true,
                    ParameterSetName='4Param')]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [Alias()] 
        [string] $InstanceId,
        
        # The host name of the queue manager service
        [Parameter(Mandatory=$true,
                    Position=2,
                    ValueFromPipeline=$true,
                    ValueFromPipelineByPropertyName=$true,
                    ParameterSetName='4Param')]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [Alias()] 
        [string] $HostName,

        # The port for the queue manager service
        [Parameter(Mandatory=$true,
                    Position=3,
                    ValueFromPipeline=$true,
                    ValueFromPipelineByPropertyName=$true,
                    ParameterSetName='4Param')]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [Alias()] 
        [Int16] $Port
    )
    
    begin {
    }
    
    process {

        $CrawlerObj = New-Object IntelliSearch.CrawlerConfiguration

        switch ($PSCmdlet.ParameterSetName) {
            "2Param" {
                $CrawlerObj.InstanceId = $InstanceId
                Write-Verbose "Creating crawler $($CrawlerObj.InstanceId)"
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "ConnectorType" -Value $Type
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "Address" -Value "net.tcp://localhost:10103/QueueManager" 
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "SetIdentifier" -Value $InstanceId
                $CrawlerObj.Enabled = $true
            }
            "4Param" {
                $CrawlerObj.InstanceId = $InstanceId
                Write-Verbose "Creating crawler $($CrawlerObj.InstanceId)"
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "ConnectorType" -Value $Type
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "Address" -Value "net.tcp://$($HostName):$($Port)/QueueManager" 
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "SetIdentifier" -Value $InstanceId
                $CrawlerObj.Enabled = $true
            }
            "xml"    {
                $CrawlerObj.InstanceId = $XmlInput.InstanceId
                Write-Verbose "Creating crawler $($CrawlerObj.InstanceId)"
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "ConnectorType" -Value "XmlFile"
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "Address" -Value $XmlInput.CustomConfiguration.ICDCrawlerConfiguration.Queues.Queue.address
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "SetIdentifier" -Value $XmlInput.CustomConfiguration.ICDCrawlerConfiguration.Queues.Queue.setIdentifier

                # Collecting extra configuration from the XML file
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "Fields" -Value $XmlInput.CustomConfiguration.ICDCrawlerConfiguration.Fields
                $CrawlerObj = $CrawlerObj | Add-Member -MemberType NoteProperty -PassThru -Name "DataRecordProcessing" -Value $XmlInput.CustomConfiguration.ICDCrawlerConfiguration.DataRecordProcessing
                $CrawlerObj.Enabled = $XmlInput.Enabled
            }
        }
        
        $CrawlerObj = $CrawlerObj | Add-Member -MemberType ScriptMethod -PassThru -Name "ToXml" -Value $ToXmlScriptblock

        $CrawlerObj
    }
    
    end {
    }
}