Public/Add-IdoItCategory.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
Function Add-IdoItCategory {
    <#
        .SYNOPSIS
        Add-IdoItCategory

        .DESCRIPTION
        With Add-CmdbCategory you can add a category object for a given object.

        .PARAMETER Id
        This parameter contains the id of the object you want to add a category

        .PARAMETER Category
        This parameter takes a constant name of a specific category

        .PARAMETER CatgId
        With CatgId you can pass an id of a global category from table isysgui_catg

        .PARAMETER CatsId
        With CatsId you can pass an id of a specific catgeory from table isysgui_cats

        .PARAMETER Data
        The data parameter takes a hashtable with all the key-value pairs of the category you want to add

        .EXAMPLE
        PS>Add-IdoItCategory -Id 3411 -Category 'C__CATG__CPU' -Data @{Title='test'}

        Adds a new category object in the category CPU for object 3411 with the value title=test

        .NOTES
        Version
        0.1.0 29.12.2017 CB initial release
    #>

        [cmdletbinding(SupportsShouldProcess=$true)]
        Param (
            [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)]
            [int]$Id,

            [Parameter(Mandatory = $true, ParameterSetName="Category")]
            [string]$Category,

            [Parameter(Mandatory = $true, ParameterSetName="CatgId")]
            [int]$CatgId,

            [Parameter(Mandatory = $true, ParameterSetName="CatsId")]
            [int]$CatsId,

            [Parameter(Mandatory=$true)]
            [Hashtable]$Data
        )

        $Params = @{}
        $Params.Add("objID", $Id)

        Switch ($PSCmdlet.ParameterSetName) {
            "Category" {$Params.Add("category", $Category); Break }
            "CatgId" {$Params.Add("catgID", $CatgId); Break }
            "CatsId" {$Params.Add("catsID", $CatsId); Break }
        }

        $Params.Add("data", $Data)

        If ($PSCmdlet.ShouldProcess("Adding category on object $Id")) {
            $ResultObj = Invoke-IdoIt -Method "cmdb.category.create" -Params $Params

            Return $ResultObj
        }
    }