Calling Synapse REST API to automate tasks using Powershell

Published Mar 11 2021 08:53 AM 3,167 Views
Microsoft

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
 
If you request the wrong token you will get error like below
 
Invoke-RestMethod: {"code":"InvalidTokenAuthenticationAudience","message":"Token Authentication failed with SecurityTokenInvalidAudienceException - IDX10214: Audience validation failed. Audiences: '[PII is hidden]'. Did not match: validationParameters.ValidAudience: '[PII is hidden]' or validationParameters.ValidAudiences: '[PII is hidden]'."}
 
You can check it in the API documentation
FonsecaSergio_0-1615481441962.png
 
FonsecaSergio_1-1615481518841.png

 

 
Find below two samples
 - Sample 1 - Get Synapse workspace (Azure Management Endpoint)
 - Sample 2 - Get Synapse SQL Pools (Synapse DEV Endpoint)
 - Sample 3 - Resume Synapse SQL Pools
 
 
 
 
 
 

Sample 1 - Get Synapse workspace (Azure Management Endpoint)

 
$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)
 
It will return JSON with data
FonsecaSergio_0-1615479391491.png

 

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": ""
    }
  ]
}
 

Sample 3 - Resume Synapse SQL Pools

 
FonsecaSergio_0-1615482556060.png

 

In this case its a little bit more trick to monitor as the resume operation is async

 

 

 

 

%3CLINGO-SUB%20id%3D%22lingo-sub-2202814%22%20slang%3D%22en-US%22%3ECalling%20Synapse%20REST%20API%20to%20automate%20tasks%20using%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2202814%22%20slang%3D%22en-US%22%3E%3CP%3ESometimes%20we%20need%20to%20do%20some%20automations%20on%20Synapse%20and%20if%20using%20Powershell%20by%20default%20use%20the%20Az%20Powershell%20Module%20to%20simplify%20this%20interaction%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.synapse%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Faz.synapse%2F%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20sometimes%20we%20need%20call%20the%20%3CSTRONG%3EREST%20APIs%20directly%3C%2FSTRONG%3E%20and%20this%20get%20the%20connectivity%20part%20a%20little%20more%20complicated%20depending%20on%20the%26nbsp%3B%3CSTRONG%3EBEARER%20TOKEN%3C%2FSTRONG%3E%20(%3CEM%3EThis%20bearer%20token%20is%20a%20lightweight%20security%20token%20that%20grants%20the%20%E2%80%9Cbearer%E2%80%9D%20access%20to%20a%20protected%20resource%3C%2FEM%3E)%20and%20you%20need%20to%20%3CSTRONG%3Erequest%20the%20token%20to%20the%20correct%20provider%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EManagement%20to%20access%20Azure%20Resources%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Frest%2Fapi%2Fsynapse%2Fworkspaces%2Fget%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Frest%2Fapi%2Fsynapse%2Fworkspaces%2Fget%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CPRE%3E%24token%26nbsp%3B%3D%26nbsp%3B(Get-AzAccessToken%26nbsp%3B-Resource%26nbsp%3B%22https%3A%2F%2F%3CSTRONG%3Emanagement.azure.com%3C%2FSTRONG%3E%22).Token%3C%2FPRE%3E%0A%3CUL%3E%0A%3CLI%3ESynapse%20DEV%20endpoint%20to%20access%20Synapse%20workspace%20resources%20(%3CSTRONG%3EResources%20that%20live%20inside%20the%20workspace%20%2F%20Pools%20%2F%20Linked%20Services%3C%2FSTRONG%3E).%26nbsp%3B%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Frest%2Fapi%2Fsynapse%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Frest%2Fapi%2Fsynapse%2F%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CDIV%3E%0A%3CPRE%3E%24token%26nbsp%3B%3D%26nbsp%3B(Get-AzAccessToken%26nbsp%3B-Resource%26nbsp%3B%22https%3A%2F%2F%3CSTRONG%3Edev.azuresynapse.net%3C%2FSTRONG%3E%22).Token%3C%2FPRE%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EIf%20you%20request%20the%20wrong%20token%20you%20will%20get%20error%20like%20below%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%20class%3D%22lia-indent-padding-left-30px%22%3E%3CEM%3EInvoke-RestMethod%3A%20%7B%22code%22%3A%22InvalidTokenAuthenticationAudience%22%2C%22message%22%3A%22Token%20Authentication%20failed%20with%20%3CSTRONG%3E%3CFONT%20color%3D%22%23FF0000%22%3ESecurityTokenInvalidAudienceException%3C%2FFONT%3E%20%3C%2FSTRONG%3E-%20IDX10214%3A%20Audience%20validation%20failed.%20Audiences%3A%20'%5BPII%20is%20hidden%5D'.%20Did%20not%20match%3A%20validationParameters.ValidAudience%3A%20'%5BPII%20is%20hidden%5D'%20or%20validationParameters.ValidAudiences%3A%20'%5BPII%20is%20hidden%5D'.%22%7D%3C%2FEM%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EYou%20can%20check%20it%20in%20the%20API%20documentation%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22FonsecaSergio_0-1615481441962.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F262823iBBC1151C702DEF98%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22FonsecaSergio_0-1615481441962.png%22%20alt%3D%22FonsecaSergio_0-1615481441962.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22FonsecaSergio_1-1615481518841.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F262824iA0D5FC2A1D3CC85F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22FonsecaSergio_1-1615481518841.png%22%20alt%3D%22FonsecaSergio_1-1615481518841.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EFind%20below%20two%20samples%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B-%26nbsp%3B%3CSTRONG%3ESample%201%20-%20Get%20Synapse%20workspace%20(Azure%20Management%20Endpoint)%3C%2FSTRONG%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B-%20%3CSTRONG%3ESample%202%20-%20Get%20Synapse%20SQL%20Pools%20(Synapse%20DEV%20Endpoint)%3C%2FSTRONG%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B-%26nbsp%3B%3CSTRONG%3ESample%203%20-%20Resume%20Synapse%20SQL%20Pools%3C%2FSTRONG%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CH2%20id%3D%22toc-hId--500265190%22%20id%3D%22toc-hId--500265190%22%3ESample%201%20-%20Get%20Synapse%20workspace%20(Azure%20Management%20Endpoint)%3C%2FH2%3E%0A%3CDIV%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FFonsecaSergio%2FScriptCollection%2Fblob%2Fmaster%2FPowershell%2FSynapse%2520-%2520REST%2520API%2520-%2520GET%2520workspace.ps1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EScriptCollection%2FSynapse%20-%20REST%20API%20-%20GET%20workspace.ps1%20at%20master%20%C2%B7%20FonsecaSergio%2FScriptCollection%20%C2%B7%20GitHub%3C%2FA%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24ResourceGroup%20%3D%20%22ResGroup%22%0A%24workspaceName%20%3D%20%22Synapse%22%0A%24SubscriptionId%20%3D%20%22de41dc76-xxxxxxx%22%0A%0A%23%20------------------------------------------%0A%23%20these%20Az%20modules%20required%0A%23%20https%3A%2F%2Fdocs.microsoft.com%2Fpowershell%2Fazure%2Finstall-az-ps%0AImport-Module%20Az.Accounts%20%0A%0A%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23CONNECT%20TO%20AZURE%0A%0A%24Context%20%3D%20Get-AzContext%0A%0Aif%20(%24Context%20-eq%20%24null)%20%7B%0A%20%20%20%20Write-Information%20%22Need%20to%20login%22%0A%20%20%20%20Connect-AzAccount%20-Subscription%20%24SubscriptionId%0A%7D%0Aelse%0A%7B%0A%20%20%20%20Write-Host%20%22Context%20exists%22%0A%20%20%20%20Write-Host%20%22Current%20credential%20is%20%24(%24Context.Account.Id)%22%0A%20%20%20%20if%20(%24Context.Subscription.Id%20-ne%20%24SubscriptionId)%20%7B%0A%20%20%20%20%20%20%20%20%24result%20%3D%20Select-AzSubscription%20-Subscription%20%24SubscriptionId%0A%20%20%20%20%20%20%20%20Write-Host%20%22Current%20subscription%20is%20%24(%24result.Subscription.Name)%22%0A%20%20%20%20%7D%0A%20%20%20%20else%20%7B%0A%20%20%20%20%20%20%20%20Write-Host%20%22Current%20subscription%20is%20%24(%24Context.Subscription.Name)%22%20%20%20%20%0A%20%20%20%20%7D%0A%7D%0A%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%0A%23%20------------------------------------------%0A%23%20get%20Bearer%20token%20for%20current%20user%20for%20Synapse%20Workspace%20API%0A%24token%20%3D%20(Get-AzAccessToken%20-Resource%20%22https%3A%2F%2Fmanagement.azure.com%22).Token%0A%24headers%20%3D%20%40%7B%20Authorization%20%3D%20%22Bearer%20%24token%22%20%7D%0A%23%20------------------------------------------%0A%0A%23https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Frest%2Fapi%2Fsynapse%2Fworkspaces%2Fget%0A%0A%24uri%20%3D%20%22https%3A%2F%2Fmanagement.azure.com%2Fsubscriptions%2F%24SubscriptionID%2F%22%0A%24uri%20%2B%3D%20%22resourceGroups%2F%24ResourceGroup%2Fproviders%2FMicrosoft.Synapse%2F%22%0A%24uri%20%2B%3D%20%22workspaces%2F%24workspaceName%2F%3Fapi-version%3D2019-06-01-preview%22%0A%0A%24result%20%3D%20Invoke-RestMethod%20-Method%20Get%20-ContentType%20%22application%2Fjson%22%20-Uri%20%24uri%20-Headers%20%24headers%0A%0AWrite-Host%20(%24result%20%7C%20ConvertTo-Json)%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3EIt%20will%20return%20JSON%20with%20data%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22FonsecaSergio_0-1615479391491.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F262814iD9D138CF20CB6006%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22FonsecaSergio_0-1615479391491.png%22%20alt%3D%22FonsecaSergio_0-1615479391491.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20you%20can%20explore%20it%20like%20a%20Powershell%20object%3C%2FP%3E%0A%3CDIV%3E%0A%3CPRE%3E%3CSPAN%3E%24result.properties.connectivityEndpoints.sql%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22FonsecaSergio_1-1615479495395.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F262815i959065B3F1C4AEC7%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22FonsecaSergio_1-1615479495395.png%22%20alt%3D%22FonsecaSergio_1-1615479495395.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1987247643%22%20id%3D%22toc-hId-1987247643%22%3ESample%202%20-%20Get%20Synapse%20SQL%20Pools%20(Synapse%20DEV%20Endpoint)%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FFonsecaSergio%2FScriptCollection%2Fblob%2Fmaster%2FPowershell%2FSynapse%2520-%2520REST%2520API%2520-%2520Get%2520Synapse%2520SQL%2520Pools%2520dev%2520endpoint.ps1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EScriptCollection%2FSynapse%20-%20REST%20API%20-%20Get%20Synapse%20SQL%20Pools%20dev%20endpoint.ps1%20at%20master%20%C2%B7%20FonsecaSergio%2FScriptCollection%20%C2%B7%20GitHub%3C%2FA%3E%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24workspaceName%20%3D%20%22Synapse%22%0A%24SubscriptionId%20%3D%20%22de41dc76-xxxxxx%22%0A%0A%23%20------------------------------------------%0A%23%20these%20Az%20modules%20required%0A%23%20https%3A%2F%2Fdocs.microsoft.com%2Fpowershell%2Fazure%2Finstall-az-ps%0AImport-Module%20Az.Accounts%20%0A%0A%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%23CONNECT%20TO%20AZURE%0A%0A%24Context%20%3D%20Get-AzContext%0A%0Aif%20(%24Context%20-eq%20%24null)%20%7B%0A%20%20%20%20Write-Information%20%22Need%20to%20login%22%0A%20%20%20%20Connect-AzAccount%20-Subscription%20%24SubscriptionId%0A%7D%0Aelse%0A%7B%0A%20%20%20%20Write-Host%20%22Context%20exists%22%0A%20%20%20%20Write-Host%20%22Current%20credential%20is%20%24(%24Context.Account.Id)%22%0A%20%20%20%20if%20(%24Context.Subscription.Id%20-ne%20%24SubscriptionId)%20%7B%0A%20%20%20%20%20%20%20%20%24result%20%3D%20Select-AzSubscription%20-Subscription%20%24SubscriptionId%0A%20%20%20%20%20%20%20%20Write-Host%20%22Current%20subscription%20is%20%24(%24result.Subscription.Name)%22%0A%20%20%20%20%7D%0A%20%20%20%20else%20%7B%0A%20%20%20%20%20%20%20%20Write-Host%20%22Current%20subscription%20is%20%24(%24Context.Subscription.Name)%22%20%20%20%20%0A%20%20%20%20%7D%0A%7D%0A%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%0A%0A%23%20------------------------------------------%0A%23%20get%20Bearer%20token%20for%20current%20user%20for%20Synapse%20Workspace%20API%0A%24token%20%3D%20(Get-AzAccessToken%20-Resource%20%22https%3A%2F%2Fdev.azuresynapse.net%22).Token%0A%24headers%20%3D%20%40%7B%20Authorization%20%3D%20%22Bearer%20%24token%22%20%7D%0A%23%20------------------------------------------%0A%0A%23%20https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Frest%2Fapi%2Fsynapse%2Fdata-plane%2Fsqlpools%2Flist%0A%23%20GET%20%7Bendpoint%7D%2FsqlPools%3Fapi-version%3D2019-06-01-preview%0A%0A%24uri%20%3D%20%22https%3A%2F%2F%24workspaceName.dev.azuresynapse.net%2F%22%0A%24uri%20%2B%3D%20%22sqlPools%3Fapi-version%3D2019-06-01-preview%22%0A%0A%24result%20%3D%20Invoke-RestMethod%20-Method%20Get%20-ContentType%20%22application%2Fjson%22%20-Uri%20%24uri%20-Headers%20%24headers%0A%0AWrite-Host%20(%24result%20%7C%20ConvertTo-Json)%0A%0A%0A%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%22value%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22properties%22%3A%20%22%40%7Bstatus%3DOnline%3B%20maxSizeBytes%3D263882790666240%3B%20collation%3DSQL_Latin1_General_CP1_CI_AS%3B%20restorePointInTime%3D01%2F01%2F0001%2000%3A00%3A00%3B%20creationDate%3D10%2F22%2F2020%2011%3A20%3A08%3B%20provisioningState%3DSucceeded%7D%22%2C%0A%20%20%20%20%20%20%22sku%22%3A%20%22%40%7Bname%3DDW100c%3B%20capacity%3D0%7D%22%2C%0A%20%20%20%20%20%20%22id%22%3A%20%22%2Fsubscriptions%2Fde41dc76-...%22%2C%0A%20%20%20%20%20%20%22name%22%3A%20%22pool01%22%2C%0A%20%20%20%20%20%20%22type%22%3A%20%22Microsoft.Synapse%2Fworkspaces%2FsqlPools%22%2C%0A%20%20%20%20%20%20%22location%22%3A%20%22westeurope%22%2C%0A%20%20%20%20%20%20%22tags%22%3A%20%22%40%7Btest%3Dtrue%7D%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22properties%22%3A%20%22%40%7Bstatus%3DPaused%3B%20maxSizeBytes%3D263882790666240%3B%20collation%3DSQL_Latin1_General_CP1_CI_AS%3B%20restorePointInTime%3D01%2F01%2F0001%2000%3A00%3A00%3B%20creationDate%3D03%2F04%2F2021%2020%3A14%3A32%3B%20provisioningState%3DFailed%7D%22%2C%0A%20%20%20%20%20%20%22sku%22%3A%20%22%40%7Bname%3DDW100c%3B%20capacity%3D0%7D%22%2C%0A%20%20%20%20%20%20%22id%22%3A%20%22%2Fsubscriptions%2Fde41dc76-....%22%2C%0A%20%20%20%20%20%20%22name%22%3A%20%22lab01%22%2C%0A%20%20%20%20%20%20%22type%22%3A%20%22Microsoft.Synapse%2Fworkspaces%2FsqlPools%22%2C%0A%20%20%20%20%20%20%22location%22%3A%20%22westeurope%22%2C%0A%20%20%20%20%20%20%22tags%22%3A%20%22%22%0A%20%20%20%20%7D%0A%20%20%5D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%0A%3CH2%20id%3D%22toc-hId-179793180%22%20id%3D%22toc-hId-179793180%22%3ESample%203%20-%20Resume%20Synapse%20SQL%20Pools%3C%2FH2%3E%0A%3C%2FDIV%3E%0A%3CDIV%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FFonsecaSergio%2FScriptCollection%2Fblob%2Fmaster%2FPowershell%2FSynapse%2520-%2520REST%2520API%2520-%2520Resume%2520SQL%2520Pool.ps1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EScriptCollection%2FSynapse%20-%20REST%20API%20-%20Resume%20SQL%20Pool.ps1%20at%20master%20%C2%B7%20FonsecaSergio%2FScriptCollection%20%C2%B7%20GitHub%3C%2FA%3E%3C%2FDIV%3E%0A%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22FonsecaSergio_0-1615482556060.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F262827i1108B966B74013CF%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22FonsecaSergio_0-1615482556060.png%22%20alt%3D%22FonsecaSergio_0-1615482556060.png%22%20%2F%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20case%20its%20a%20little%20bit%20more%20trick%20to%20monitor%20as%20the%20resume%20operation%20is%20async%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2202814%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESynapse%20Administration%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESynapse%20DevOps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎Mar 11 2021 09:11 AM
Updated by: