Public/Policies/New-SCAAccessPolicy.ps1

function New-SCAAccessPolicy {
    <#
    .SYNOPSIS
        Creates an access control policy.
    .DESCRIPTION
        Calls POST /policies on the Access Control Policies API to create a new policy governing
        cloud console, infrastructure, database, or group access. The request body must match one
        of CyberArk's documented policy schemas (CloudConsoleAccessPolicy for SCA cloud console
        access, InfrastructureVirtualMachineAccessPolicy, InfrastructureDatabaseAccessPolicy, or
        GroupAccessPolicy); see the .LINK below for the current schema definitions.
    .PARAMETER InputObject
        The policy document to create, as a hashtable or PSCustomObject matching CyberArk's policy
        schema.
    .PARAMETER Session
        A psSCA.Session object or session name. Defaults to the current default session.
    .EXAMPLE
        $policy = @{
            name = 'AWS Production Read-Only'
            status = 'Active'
            entitlement = @{ targetCategory = 'CloudConsole' }
        }
        New-SCAAccessPolicy -InputObject $policy

        Creates a new access control policy. The exact required fields depend on the target
        category; confirm against CyberArk's schema before running this against a production
        tenant.
    .INPUTS
        System.Object. Accepts a policy document via the pipeline.
    .OUTPUTS
        psSCA.AccessPolicy
    .NOTES
        Confirm the exact request body fields against CyberArk's published schema before relying
        on this in an automated pipeline.
    .LINK
        https://api-docs.cyberark.com/uap-schema-api/docs/access-control-policies-api
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
    [OutputType('psSCA.AccessPolicy')]
    param(
        [Parameter(Mandatory, ValueFromPipeline)]
        [object]$InputObject,

        [Parameter()]
        [object]$Session
    )

    process {
        $name = if ($InputObject -is [hashtable]) { $InputObject['name'] } else { $InputObject.name }
        $target = if ($name) { $name } else { 'new access policy' }

        if ($PSCmdlet.ShouldProcess($target, 'Create Secure Cloud Access policy')) {
            Invoke-SCARequest -Session $Session -Service 'UAP' -Method POST -Path '/policies' `
                -Body $InputObject -Operation 'New-SCAAccessPolicy' -TypeName 'psSCA.AccessPolicy'
        }
    }
}