AndrewPla / TOPdeskPS

PowerShell module to interact with the TOPdesk API
MIT License
30 stars 12 forks source link

archive/unarchive asset. #124

Open cvvcvv opened 1 year ago

cvvcvv commented 1 year ago

Hi, many thanks for this PS module. But I am missing the cmdlet for archive/unarchive asset.

So I adjusted the esxiting set-tdasset function. Maybe you can add them to the module?

function archive-TdAsset { <# .SYNOPSIS Archives an asset adjusted .DESCRIPTION Updates the given asset.It may be possible that one or more assets couldn’t be deleted because they have existing links from other components. In this case those assets’ ids will be listed in the ‘failed’ list of the response, but it doesn’t affect deletion of other assets. .PARAMETER AssetId Id of the asset to update .PARAMETER Body This object contains key-value pairs, where the key is the modified field’s id, and the value is the new value. If a mandatory field is not given in this model, then it’s value remains the same. Example: @{ "reasonId" = "469c1d1a-9fdf-5f67-914c-2443e73cb2d8"; } .PARAMETER Confirm If this switch is enabled, you will be prompted for confirmation before executing any operations that change state. .PARAMETER WhatIf If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run. .EXAMPLE PS C:> Set-TdAsset -AssetId $AssetId Removes all assets with id's inside $assetId.

>

[CmdletBinding(HelpUri = 'https://andrewpla.github.io/TOPdeskPS/commands/TOPdeskPS/archive-TdAsset',
    SupportsShouldProcess = $true)]
param
(
    [Parameter(Mandatory = $true,
        ValueFromPipelineByPropertyName = $true)]
    [Alias('Id')]
    [system.string]
    $AssetId,

    [Parameter(Mandatory)]
    [pscustomobject]$Body

    #TODO add parameters for status, statuslocked, and etag as shortcuts to quickly spin up a body for the request.
)

process {
    Write-PSFMessage -Level InternalComment -Message "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"

    $uri = (Get-TdUrl) + "/tas/api/assetmgmt/assets/$AssetId/archive"

    Write-PSFMessage "$($Body | ConvertTo-Json | Out-String)" -Level debug
    $params = @{
        'Uri' = $uri
        'Body' = $Body | ConvertTo-Json
        'Method' = 'Post'
    }
    if (-not (Test-PSFShouldProcess -PSCmdlet $PSCmdlet -Target $uri -Action 'Updating asset.')) {
        return
    }
    Invoke-TdMethod @params
}

}

function unarchive-TdAsset { <# .SYNOPSIS Archives an asset adjusted CVV .DESCRIPTION Updates the given asset.It may be possible that one or more assets couldn’t be deleted because they have existing links from other components. In this case those assets’ ids will be listed in the ‘failed’ list of the response, but it doesn’t affect deletion of other assets. .PARAMETER AssetId Id of the asset to update .PARAMETER Confirm If this switch is enabled, you will be prompted for confirmation before executing any operations that change state. .PARAMETER WhatIf If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run. .EXAMPLE PS C:> Set-TdAsset -AssetId $AssetId Removes all assets with id's inside $assetId.

>

[CmdletBinding(HelpUri = 'https://andrewpla.github.io/TOPdeskPS/commands/TOPdeskPS/archive-TdAsset',
    SupportsShouldProcess = $true)]
param
(
    [Parameter(Mandatory = $true,
        ValueFromPipelineByPropertyName = $true)]
    [Alias('Id')]
    [system.string]
    $AssetId

    #TODO add parameters for status, statuslocked, and etag as shortcuts to quickly spin up a body for the request.
)

process {
    Write-PSFMessage -Level InternalComment -Message "[$($MyInvocation.MyCommand.Name)] PSBoundParameters: $($PSBoundParameters | Out-String)"

    $uri = (Get-TdUrl) + "/tas/api/assetmgmt/assets/$AssetId/unarchive"

    Write-PSFMessage "$($Body | ConvertTo-Json | Out-String)" -Level debug
    $params = @{
        'Uri' = $uri
        'Method' = 'Post'
    }
    if (-not (Test-PSFShouldProcess -PSCmdlet $PSCmdlet -Target $uri -Action 'Updating asset.')) {
        return
    }
    Invoke-TdMethod @params
}

}