Public/AuditLogging/Set-R1AuditLogSetting.ps1

# .ExternalHelp psRadiantOne-help.xml
function Set-R1AuditLogSetting {
    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
    [OutputType([void])]
    param(
        [parameter(
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true
        )]
        [bool]$enabled,

        [parameter(
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true
        )]
        [bool]$diffsEnabled,

        [parameter(
            Mandatory = $false,
            ValueFromPipelineByPropertyName = $true
        )]
        [bool]$jsonEnabled
    )

    Begin {

        Assert-R1Session -RequireToken

    }#begin

    Process {

        $URI = Resolve-R1ServiceUrl -Service Settings -Path 'audit_logs/configuration'

        #Retrieve the current configuration and send it back with the supplied values applied over it,
        #so a setting left unspecified keeps its current value.
        $Existing = Get-R1AuditLogSetting

        $Template = [ordered]@{
            enabled      = $false
            diffsEnabled = $false
            jsonEnabled  = $false
        }

        $Request = Merge-R1Parameter -Template $Template -BoundParameter ($PSBoundParameters | Get-Parameter) -Fallback $Existing

        $Body = $Request | ConvertTo-R1JsonBody

        if ($PSCmdlet.ShouldProcess($Script:psRadiantOneSession.BaseURI, 'Update Audit Log Configuration')) {

            $null = Invoke-R1RestMethod -Uri $URI -Method PUT -Body $Body

        }

    }#process

    End { }#end

}