Functions/Export-DatabricksClusterByNameAsJson.ps1

<#
.SYNOPSIS
Exports DataBricks Clusters and Saves as json.
 
.DESCRIPTION
Exports Databricks Clusters and saves as json.
 
.PARAMETER BearerToken
Your Databricks Bearer token to authenticate to your workspace (see User Settings in Datatbricks WebUI)
 
.PARAMETER Region
Azure Region - must match the URL of your Databricks workspace, example northeurope
 
.PARAMETER ClusterName
The name of the cluster to export as a json file.
 
.PARAMETER LocalOutputPath
Local directroy to save json files.
 
.EXAMPLE
 
.NOTES
Author: Sabin IO
 
#>
 
Function Export-DatabricksClusterByNameAsJson {  
    [cmdletbinding()]
    Param(
       # [parameter(Mandatory = $false)][string]$BearerToken,
        #[parameter(Mandatory = $false)][string]$Region,
        [parameter(Mandatory = $true)][string]$ClusterName,
        [parameter(Mandatory = $true)][string]$LocalOutputPath
    )
    

    $cluster = Get-DatabricksClusterSingletonByName -ClusterName $ClusterName
    
    $clusterFileName = (Remove-UnwantedFilenameChars $clusterName) + '.cluster.config.json'

    # Remove meta data from cluster as these change all the time
    # IE start_time, state
    $tmp = $cluster | Remove-ClusterMetaDataAsPSObject
    $clusterAsJson = $tmp | ConvertTo-OrderedHashtableFromPSCustomObject | ConvertTo-Json -Depth 100
    
    $LocalExportPath = Join-Path $LocalOutputPath $clusterFileName
    Write-Verbose "Exporting clusters to $LocalExportPath"
    New-Item -Force -Path $LocalExportPath -Value $clusterAsJson -Type file | Out-Null 
}