Sometimes we need to do some automations on Synapse and if using Powershell by default use the Az Powershell Module to simplify this interaction
https://docs.microsoft.com/en-us/powershell/module/az.synapse/
But sometimes we need call the REST APIs directly and this get the connectivity part a little more complicated depending on the BEARER TOKEN (This bearer token is a lightweight security token that grants the “bearer” access to a protected resource) and you need to request the token to the correct provider
$token = (Get-AzAccessToken -Resource "https://management.azure.com").Token
$token = (Get-AzAccessToken -Resource "https://dev.azuresynapse.net").Token
$ResourceGroup = "ResGroup"
$workspaceName = "Synapse"
$SubscriptionId = "de41dc76-xxxxxxx"
# ------------------------------------------
# these Az modules required
# https://docs.microsoft.com/powershell/azure/install-az-ps
Import-Module Az.Accounts
#########################################################################################CONNECT TO AZURE
$Context = Get-AzContext
if ($Context -eq $null) {
Write-Information "Need to login"
Connect-AzAccount -Subscription $SubscriptionId
}
else
{
Write-Host "Context exists"
Write-Host "Current credential is $($Context.Account.Id)"
if ($Context.Subscription.Id -ne $SubscriptionId) {
$result = Select-AzSubscription -Subscription $SubscriptionId
Write-Host "Current subscription is $($result.Subscription.Name)"
}
else {
Write-Host "Current subscription is $($Context.Subscription.Name)"
}
}
########################################################################################
# ------------------------------------------
# get Bearer token for current user for Synapse Workspace API
$token = (Get-AzAccessToken -Resource "https://management.azure.com").Token
$headers = @{ Authorization = "Bearer $token" }
# ------------------------------------------
#https://docs.microsoft.com/en-us/rest/api/synapse/workspaces/get
$uri = "https://management.azure.com/subscriptions/$SubscriptionID/"
$uri += "resourceGroups/$ResourceGroup/providers/Microsoft.Synapse/"
$uri += "workspaces/$workspaceName/?api-version=2019-06-01-preview"
$result = Invoke-RestMethod -Method Get -ContentType "application/json" -Uri $uri -Headers $headers
Write-Host ($result | ConvertTo-Json)
But you can explore it like a Powershell object
$result.properties.connectivityEndpoints.sql
$workspaceName = "Synapse"
$SubscriptionId = "de41dc76-xxxxxx"
# ------------------------------------------
# these Az modules required
# https://docs.microsoft.com/powershell/azure/install-az-ps
Import-Module Az.Accounts
########################################################################################
#CONNECT TO AZURE
$Context = Get-AzContext
if ($Context -eq $null) {
Write-Information "Need to login"
Connect-AzAccount -Subscription $SubscriptionId
}
else
{
Write-Host "Context exists"
Write-Host "Current credential is $($Context.Account.Id)"
if ($Context.Subscription.Id -ne $SubscriptionId) {
$result = Select-AzSubscription -Subscription $SubscriptionId
Write-Host "Current subscription is $($result.Subscription.Name)"
}
else {
Write-Host "Current subscription is $($Context.Subscription.Name)"
}
}
########################################################################################
# ------------------------------------------
# get Bearer token for current user for Synapse Workspace API
$token = (Get-AzAccessToken -Resource "https://dev.azuresynapse.net").Token
$headers = @{ Authorization = "Bearer $token" }
# ------------------------------------------
# https://docs.microsoft.com/en-us/rest/api/synapse/data-plane/sqlpools/list
# GET {endpoint}/sqlPools?api-version=2019-06-01-preview
$uri = "https://$workspaceName.dev.azuresynapse.net/"
$uri += "sqlPools?api-version=2019-06-01-preview"
$result = Invoke-RestMethod -Method Get -ContentType "application/json" -Uri $uri -Headers $headers
Write-Host ($result | ConvertTo-Json)
{
"value": [
{
"properties": "@{status=Online; maxSizeBytes=263882790666240; collation=SQL_Latin1_General_CP1_CI_AS; restorePointInTime=01/01/0001 00:00:00; creationDate=10/22/2020 11:20:08; provisioningState=Succeeded}",
"sku": "@{name=DW100c; capacity=0}",
"id": "/subscriptions/de41dc76-...",
"name": "pool01",
"type": "Microsoft.Synapse/workspaces/sqlPools",
"location": "westeurope",
"tags": "@{test=true}"
},
{
"properties": "@{status=Paused; maxSizeBytes=263882790666240; collation=SQL_Latin1_General_CP1_CI_AS; restorePointInTime=01/01/0001 00:00:00; creationDate=03/04/2021 20:14:32; provisioningState=Failed}",
"sku": "@{name=DW100c; capacity=0}",
"id": "/subscriptions/de41dc76-....",
"name": "lab01",
"type": "Microsoft.Synapse/workspaces/sqlPools",
"location": "westeurope",
"tags": ""
}
]
}
In this case its a little bit more trick to monitor as the resume operation is async
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.