Functions/Internal/Remove-JobMetaDataAsPSObject.ps1

function Remove-JobMetaDataAsPSObject {
    [CmdletBinding()]
    param ( 
        [Parameter(  
            Position = 0,   
            Mandatory = $true,   
            ValueFromPipeline = $true,  
            ValueFromPipelineByPropertyName = $true  
        )] [PSObject]$customObject
    );
    process{
    <# Allowed values for Job Settings #>
    <# See - https://docs.microsoft.com/en-gb/azure/databricks/dev-tools/api/latest/jobs#--jobsettings #>
    $allowedValues = @('existing_cluster_id', 'new_cluster', 'notebook_task', 'spark_jar_task', 'spark_python_task', 'spark_submit_task', 
        'name', 'libraries', 'email_notifications', 'timeout_seconds', 'max_retries', 'min_retry_interval_millis', 'retry_on_timeout',
        'schedule', 'max_concurrent_runs', 'existing_cluster_name'
    )
    <# N.B. #>
    <# existing_cluster_name is unique to mars as there are multiple workspaces so we store the name and not the id #>

    <# Remove any properties that are not defined in the allowedValues array #>
    foreach ($prop in $customObject.PSObject.Properties) {
        Write-Verbose "Property Name: $($prop.Name)"
        if ($prop.Name -notin $allowedValues) {
            $customObject.PSObject.Properties.Remove($prop.Name)     
            Write-Verbose "[Removing] property $($prop.Name) from Job Configuration."
        }
    }

    return $customObject
}
}