Functions/Export-DatabricksClustersFromWorkspace.ps1
<#
.SYNOPSIS Exports DataBricks Clusters and Saves as json. .DESCRIPTION Exports Databricks Clusters and saves as json. .PARAMETER config Configuration json file from the environment to use for possible clusters to remove. .PARAMETER localOutputPath The name of the cluster to export as a json file. .EXAMPLE Export-DatabricksClustersFromWorkspace -config $config -bearerToken 'dapi1234567890' -LocalOutputPath '.\output' .NOTES Author: Sabin IO #> Function Export-DatabricksClustersFromWorkspace { [cmdletbinding()] Param( [parameter(Mandatory = $true)]$config, [parameter(Mandatory = $true)][string]$localOutputPath ) try { $clusters = Get-DatabricksClusters $noneExistantClusters = @() $existentClusters = @() if ($config.getClustersByName) { Write-Verbose "getClustersByName config key supplied" if ($config.getClustersByName.Length -ge 1) { if ($config.getClustersByName[0].ToString().ToUpper() -eq "ALL") { Write-Verbose "All parameter supplied. Pulling all cluster configurations." foreach ($cluster in $clusters) { Export-DatabricksClusterByNameAsJson -ClusterName $cluster.cluster_name -LocalOutputPath $localOutputPath -Verbose } } else { # Check if clusters exist in the first place foreach ($cluster in $config.getClustersByName) { if ($cluster -notin $clusters.cluster_name) { $noneExistantClusters += $cluster } else { $existentClusters += $cluster } } if ($noneExistantClusters) { Write-Warning "There are clusters that do not exist to get, These will be skipped. `n`n $($noneExistantClusters)" } # If we've got this far, it should mean we are good to export all the known clusters by name foreach ($cluster in $existentClusters) { Export-DatabricksClusterByNameAsJson -ClusterName $cluster -LocalOutputPath $localOutputPath -Verbose } } } } else { Write-Verbose "getClustersByName config key not supplied" } } catch { #uh oh throw $_.Exception } } |