Functions/Remove-DatabricksClusterLibrariesFromWorkspaceByName.ps1
<#
.SYNOPSIS Removes DataBricks Cluster Libraries from environment configuration .DESCRIPTION Removes DataBricks Cluster Libraries from environment configuration. .PARAMETER config Configuration json file from the environment. .PARAMETER bearerToken Your Databricks Bearer token to authenticate to your workspace (see User Settings in Datatbricks WebUI) .PARAMETER librariesConfig The name libraries config you want to remove/uninstall The format has to be specified here: https://docs.microsoft.com/en-gb/azure/databricks/dev-tools/api/latest/libraries#--uninstall .EXAMPLE Remove-DatabricksClusterLibrariesFromWorkspaceByName -config $config -bearerToken 'dapi1234567890' -librariesConfig '<PSObject>' .NOTES Author: Sabin IO #> Function Remove-DatabricksClusterLibrariesFromWorkspaceByName { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', 'global:DatabricksURI')] [cmdletbinding()] Param( [parameter(Mandatory = $true)]$config, [parameter(Mandatory = $true)][string]$bearerToken, [parameter(Mandatory = $true)][psobject]$librariesConfig ) try { Connect-Databricks -BearerToken $bearerToken -Region $config.region $ClusterId = (Get-DatabricksClusters | Where-Object { $_.cluster_name -eq $librariesConfig.cluster_name }).cluster_id $librariesConfig.PSObject.Properties.Remove('cluster_name') $librariesConfig | Add-Member -NotePropertyName 'cluster_id' -NotePropertyValue $ClusterId [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Headers = Get-Headers $PSBoundParameters # TODO: Replace API call with call to azure.databricks.cicd.tools $uri = "$global:DatabricksURI/api/2.0/libraries/uninstall" $BodyText = $librariesConfig | ConvertTo-Json -Depth 100 Write-Output "Request Body: $BodyText" Write-Output "UnInstalling libraries..." $Response = Invoke-RestMethod -Uri $uri -Body $BodyText -Method 'POST' -Headers $Headers return $Response } catch { #uh oh throw $_.Exception } } |