Admin/Item/Set-SDPItem.ps1

Function Set-SDPItem
{
    <#
    .SYNOPSIS
        Update Item
 
    .PARAMETER ItemId
        Item id
 
    .PARAMETER InputData
        Input data as hashtable or JSON string
 
    .EXAMPLE
        $InputData = @{
            item = @{
                name = "Testowy Incydent bezpieczeĹ„stwa"
                description = "Testowy"
                subcategory = @{
                    id = 3003
                }
            }
        }
 
        $Item = Set-SDPItem -ItemId 54321 -InputData $InputData
 
    .NOTES
        Author: Michal Gajda
 
    .LINK
        https://ui.servicedeskplus.com/APIDocs3/index.html#update-an-user
    #>

    [CmdletBinding(
        SupportsShouldProcess=$True,
        ConfirmImpact="Low"
    )]
    param (
        [String]$UriSDP,
        [String]$ApiKey,
        [Parameter(Mandatory=$true,
            ValueFromPipeline)]
        [Int]$ItemId,
        [Parameter(Mandatory=$true)]
        $InputData
    )

    Begin
    {
        #Create headers
        if(!$MyInvocation.BoundParameters.ContainsKey("UriSDP")) { $UriSDP = $Global:UriSDP }
        if(!$MyInvocation.BoundParameters.ContainsKey("ApiKey")) { $ApiKey = $Global:ApiKey }
    }

    Process
    {
        $InvokeParams = @{
            UriSDP = $UriSDP
            ApiKey = $ApiKey
            Method = "PUT"
            EntityUri = "/api/v3/items/$ItemId"
            InputData = $InputData
        }

        #Send request
        If ($PSCmdlet.ShouldProcess($ItemId,"Update item by id"))
        {
            $Result = Invoke-SDPAPIEntity @InvokeParams
            $Results = $Result.item
        }

        #Return result
        if($MyInvocation.BoundParameters.ContainsKey("Debug"))
        {
            Return $Result
        } else {
            Return $Results
        }
    }

    End{}
}