Functions/Get-DatabricksClusterSingletonByName.ps1
<#
.SYNOPSIS Get a Single Databricks Cluster .DESCRIPTION Get a Single Databricks Cluster .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 return. .EXAMPLE PS C:\> Get-DatabricksCluster -BearerToken 'dapi1234567890' -Region 'eastus2' -ClusterName 'cluster name' Returns a Single cluster .NOTES Author: Sabin IO #> Function Get-DatabricksClusterSingletonByName { [cmdletbinding()] param ( [parameter(Mandatory = $true, ParameterSetName = 'Bearer')] [string]$BearerToken, [parameter(Mandatory = $true)] [string]$ClusterName, [parameter(Mandatory = $false, ParameterSetName = 'Bearer')] [parameter(Mandatory = $false, ParameterSetName = 'AAD')] [string]$Region, $databricksURI ) [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Headers = GetHeaders $PSBoundParameters Try { $ClusterId = (Get-DatabricksClusters | Where-Object { $_.cluster_name -eq $ClusterName }).cluster_id $Cluster = Invoke-RestMethod -Method Get -Uri "$databricksURI/api/2.0/clusters/get?cluster_id=$ClusterId" -Headers $Headers } Catch { Write-Error "StatusCode:" $_.Exception.Response.StatusCode.value__ Write-Error "StatusDescription:" $_.Exception.Response.StatusDescription Write-Error $_.ErrorDetails.Message } return $Cluster } |