Public/Get-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
#requires -version 4

function ModuleRoot { $MyInvocation.ScriptName | Split-Path -Parent}

. $PSScriptRoot\New-ISCrawler.ps1

<#
.SYNOPSIS
    Gets configured ICD crawlers
.DESCRIPTION
    The Get-ISCrawler cmdlet parses a CrawlerConfig.xml file and returns objects representing the configured crawlers.
.EXAMPLE
    Get-ISCrawler "C:\Program Files\IntelliSearch\ESP-1\Config\CrawlerConfig.xml"
.INPUTS
    System.String
.OUTPUTS
    Crawler
#>

function Get-ISCrawler {
    [CmdletBinding(DefaultParameterSetName='Parameter Set 1',
                   SupportsShouldProcess=$false,
                   PositionalBinding=$false,
                   ConfirmImpact='None')]
    [Alias()]
    Param (
        # The path to the CrawlerConfig.xml file
        [Parameter(Mandatory=$true,
                   Position=0,
                   ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true,
                   ValueFromRemainingArguments=$false, 
                   ParameterSetName='Parameter Set 1')]
        [ValidateNotNull()]
        [ValidateNotNullOrEmpty()]
        [Alias()] 
        [string] $Path
    )

    process {
        $Path = Resolve-Path $Path

        $xml = New-Object XML
        $xml.Load($Path)

        # Create XML namespaces for use when searching for the correct node to remove.
        # Prepend "ns:" to the node to search for
        $XmlNamespace = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
        $XmlNamespace.AddNamespace("ns", $xml.DocumentElement.NamespaceURI)

        $Nodes = $xml.SelectNodes("//ns:Crawler", $XmlNamespace)
        
        # Removing the namespace for consistency
        $XmlNamespace.RemoveNamespace("ns", $xml.NamespaceURI)

        foreach ($XmlCrawler in $Nodes) {
            Write-Verbose "Processing crawler: $($XmlCrawler.InstanceId)"
            New-ISCrawler -XmlInput $XmlCrawler
        }
    }
}