Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ADFv2 LinkedService Test
function connect($SubscriptionID)
{
if($null -eq (Get-AzureRMContext).Account)
{
Connect-AzureRmAccount
Select-AzureRmSubscription -Subscription $SubscriptionID
}
}
function getBearer([string]$TenantID, [string]$ClientID, [string]$ClientSecret)
{
$TokenEndpoint = {https://login.windows.net/{0}/oauth2/token} -f $TenantID
$ARMResource = "https://management.core.windows.net/";
$Body = @{
'resource'= $ARMResource
'client_id' = $ClientID
'grant_type' = 'client_credentials'
'client_secret' = $ClientSecret
}
$params = @{
ContentType = 'application/x-www-form-urlencoded'
Headers = @{'accept'='application/json'}
Body = $Body
Method = 'Post'
URI = $TokenEndpoint
}
$token = Invoke-RestMethod @params
Return "Bearer " + ($token.access_token).ToString()
}
function getLinkedService([string]$LinkedService)
{
$ADFEndpoint = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroup/providers/Microsoft.DataFactory/factories/$DataFactoryName/linkedservices/$($LinkedService)?api-version=2018-06-01"
$params = @{
ContentType = 'application/json'
Headers = @{'accept'='application/json';'Authorization'=$BearerToken}
Method = 'GET'
URI = $ADFEndpoint
}
$a = Invoke-RestMethod @params
Return ConvertTo-Json -InputObject @{"linkedService" = $a} -Depth 10
}
function testLinkedServiceConnection($Body)
{
$AzureEndpoint = "https://management.azure.com/subscriptions/$SubscriptionID/resourcegroups/$ResourceGroup/providers/Microsoft.DataFactory/factories/$DataFactoryName/testConnectivity?api-version=2017-09-01-preview"
$params = @{
ContentType = 'application/json'
Headers = @{'accept'='application/json';'Authorization'=$BearerToken}
Body = $Body
Method = 'Post'
URI = $AzureEndpoint
}
Return (Invoke-RestMethod @params).succeeded
}
# These are dummy secrets!
$ClientID = "d8e4efe0-f335-4da8-9adb-38942dca3783"
$ClientSecret = "TNALx46f08RIMui8iUvTCFbbWb/yIS+AQA1WlwBN7oo="
$DataFactoryName = "dataThirstADFv2Test1"
$ResourceGroup = "dataThirstTestBed8"
$SubscriptionID = "d4c56897-10e7-4c62-a139-326bcf267f68"
connect $SubscriptionID
$BearerToken = getBearer "bb0280d2-a9cf-46e8-9485-19d65b1b2c84" $ClientID $ClientSecret
$LinkedServiceBody = getLinkedService "LS_DataThirst_TestBed8_ADLS"
testLinkedServiceConnection $LinkedServiceBody
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.