Public/Get-IdoItObjectTypeCategory.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
Function Get-IdoItObjectTypeCategory {
    <#
    .SYNOPSIS
    Get-IdoItObjectTypeCategory

    .DESCRIPTION
    Calling this Cmdlet you retreive all the available Categories for this object type

    .PARAMETER Type
    Defines the type id you wan't to retreive the configured categories

    .EXAMPLE
    PS> Get-IdoItObjectTypeCategory -Type 'C__OBJTYPE__SERVER'

    This will get all aategories that are assigned to the ObjectType 'Server'

    .NOTES
    Version
    0.1.0 29.12.2017 CB initial release
    #>

    [CmdletBinding()]
    [OutputType([System.Object[]])]
    Param (
        [Parameter (
            Mandatory = $True,
            ValueFromPipeline = $True,
            Position = 0
        )]
        [Alias("TypeId")]
        $Type
    )

    Process {

        $Params = @{}
        $Params.Add("type", $Type)

        $ResultObj = Invoke-IdoIt -Method "cmdb.object_type_categories.read" -Params $Params

        #idoit delivers two arrays, depending of global or specific categories. From a PowerShell
        #point of view this is ugly - so we flatten the result into one PSObject.

        $ModifiedResultObj = @()
        ForEach ($o In $ResultObj.PSObject.Properties) {

            ForEach ($p In $ResultObj.($o.Name)) {
                $TempObj = $p
                $TempObj | Add-Member -MemberType NoteProperty -Name "type" -Value $o.Name
                $ModifiedResultObj += $TempObj
            }

        }

        $ModifiedResultObj = $ModifiedResultObj | Add-ObjectTypeName -TypeName 'IdoIt.ObjectTypeCategory'

        Return $ModifiedResultObj
    }
}