Public/Policies/Set-SIAAccessPolicy.ps1

function Set-SIAAccessPolicy {
    <#
    .SYNOPSIS
        Updates a legacy SIA VM access policy.
    .DESCRIPTION
        Updates a policy in SIA's original "Recurring access policies" engine.
        Only applies to tenants still on that engine; see
        docs/API-COMPATIBILITY.md. Only the parameters you supply are sent.
    .PARAMETER Id
        The policy's ID, as returned by Get-SIAAccessPolicy.
    .PARAMETER PolicyName
        A new display name for the policy, 1-300 characters.
    .PARAMETER Description
        A description of the policy.
    .PARAMETER Status
        The policy status. An active policy is 'Enabled'; set 'Disabled' to
        suspend it.
    .PARAMETER StartDate
        When the policy becomes active.
    .PARAMETER EndDate
        When the policy expires.
    .PARAMETER ProvidersData
        Cloud provider-specific policy data.
    .PARAMETER UserAccessRules
        The access rules specifying the access profile, which members can
        assume it, and when users are allowed to access the assets.
    .EXAMPLE
        Set-SIAAccessPolicy -Id 'policy-01' -Status Disabled

        Suspends the specified legacy access policy.
    .INPUTS
        psSIA.AccessPolicy
    .OUTPUTS
        psSIA.AccessPolicy
    .LINK
        https://docs.cyberark.com/setup/latest/en/content/privileged-access/apis/dpa_policies.htm
    #>

    [CmdletBinding(SupportsShouldProcess)]
    [OutputType('psSIA.AccessPolicy')]
    param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [Alias('policy_id')]
        [string]$Id,

        [ValidateLength(1, 300)]
        [string]$PolicyName,

        [string]$Description,

        [ValidateSet('Irrelevant', 'Enabled', 'Disabled', 'Draft', 'Expired')]
        [string]$Status,

        [datetime]$StartDate,

        [datetime]$EndDate,

        [hashtable]$ProvidersData,

        [array]$UserAccessRules
    )

    process {
        $body = @{}
        if ($PSBoundParameters.ContainsKey('PolicyName')) { $body.policyName = $PolicyName }
        if ($PSBoundParameters.ContainsKey('Description')) { $body.description = $Description }
        if ($PSBoundParameters.ContainsKey('Status')) { $body.status = $Status }
        if ($PSBoundParameters.ContainsKey('StartDate')) { $body.startDate = $StartDate.ToString('o') }
        if ($PSBoundParameters.ContainsKey('EndDate')) { $body.endDate = $EndDate.ToString('o') }
        if ($PSBoundParameters.ContainsKey('ProvidersData')) { $body.providersData = $ProvidersData }
        if ($PSBoundParameters.ContainsKey('UserAccessRules')) { $body.userAccessRules = $UserAccessRules }

        if ($PSCmdlet.ShouldProcess($Id, 'Update legacy access policy')) {
            Invoke-SIARequest -Method PUT -Path "/api/access-policies/$Id" -Body $body |
                ConvertFrom-SIAResponse -TypeName 'psSIA.AccessPolicy'
        }
    }
}