Public/Set-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
52
53
54
55
56
57
58
59
Function Set-IdoItObject {
    <#
        .SYNOPSIS
        Set-IdoItObject

        .DESCRIPTION
        Set-IdoItObject lets you modify an existing objects title .

        .PARAMETER Id
        This parameter either the type id of the object you want to modify.

        .PARAMETER Title
        Defines the new title for the object you are modifing.

        .EXAMPLE
        PS> Set-IdoItObject -Id 1234 -Title "srv12345.domain.de"

        This will change the title for object 1234 to srv12345.domain.de

        .NOTES
        Version
        0.1.0 29.12.2017 CB initial release
    #>

        [CmdletBinding( SupportsShouldProcess=$True )]
        Param (
            [Parameter( Mandatory=$True,
                        ValueFromPipelineByPropertyName,
                        Position=0)]
            [Int]$Id,

            [Parameter( Mandatory=$True )]
            [String]$Title
        )

        Process {

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


            $Params.Add("title", $Title)

            If (Get-IdoItObject -Id $Object) {

                If ($PSCmdlet.ShouldProcess("Updating title for object id $Id to $Title")) {
                    $ResultObj = Invoke-IdoIt -Method "cmdb.object.update" -Params $Params
                }

                If ($ResultObj.success) {
                    Return $ResultObj.message
                }

            }
            Else {
                Write-Error -Message "Could not find object id $Id."
            }
        }

    }