Public/Find-IdoItObject.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
Function Find-IdoItObject {
    <#
        .SYNOPSIS
        With Find-IdoItObject you can trigger a global search over the i-doit API.

        .DESCRIPTION
        With Find-IdoItObject you can trigger a global search over the i-doit API.

        .PARAMETER Query
        This parameter defines the query to search for.

        .EXAMPLE
        PS> Find-IdoItObject -Query "server"

        This command will return all objects that have "server" in their name.

        .NOTES
        Version
        0.1.0 29.12.2017 CB initial release
    #>

        Param (
            [Parameter(Mandatory = $true, Position=0)]
            [String]$Query
        )

        #TODO Add CheckCmdbConnection again
        #checkCmdbConnection

        $Params  = @{
            "q"      = $Query
        }

        #Create an empty PSObject array to store the results
        $ResultObj = @(New-Object PSObject)
        $ResultObj = Invoke-IdoIt -Method "idoit.search" -Params $Params

        #Thank synetics for being inconsistent about naming properties. We replace documentId to id, value to title
        foreach ($o in $ResultObj) {
            $o | Add-Member -MemberType NoteProperty -Name "id" -Value $o.DocumentId
            $o | Add-Member -MemberType NoteProperty -Name "title" -Value $o.Value
            $o.PSObject.Properties.Remove("documentId")
            $o.PSObject.Properties.Remove("value")
        }

        $ResultObj = $ResultObj | Add-ObjectTypeName -TypeName 'Idoit.Object.SearchResult'
        $ResultObj = $ResultObj | Add-ObjectDefaultPropertySet -DefaultProperties 'Id','Title','Link','Score'

        Return $ResultObj


    }