Functions/Internal/Remove-ClusterMetaDataAsPSObject.ps1

function Remove-ClusterMetaDataAsPSObject {
    [CmdletBinding()]
    param ( 
        [Parameter(  
            Position = 0,   
            Mandatory = $true,   
            ValueFromPipeline = $true,  
            ValueFromPipelineByPropertyName = $true  
        )] [PSObject]$customObject
    );
    process {
        # Allowed values for Creating a Cluster
        # See - https://docs.microsoft.com/en-gb/azure/databricks/dev-tools/api/latest/clusters#--request-structure
        $allowedValues = @('num_workers', 'autoscale', 'cluster_name', 'spark_version', 'spark_conf', 'node_type_id' `
                , 'driver_node_type_id', 'custom_tags', 'cluster_log_conf', 'init_scripts', 'docker_image', 'spark_env_vars' `
                , 'autotermination_minutes', 'instance_pool_id', 'idempotency_token'
        )

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

        return $customObject
    }
}