public/Test-AdfLinkedService.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function Test-AdfLinkedService {
    [CmdletBinding()]
    param (
        [parameter(Mandatory = $true)] 
        [String] $LinkedServiceName,
        [parameter(Mandatory = $true)] 
        [String] $DataFactoryName,
        [parameter(Mandatory = $true)] 
        [String] $ResourceGroupName,
        [parameter(Mandatory = $true)] 
        [String] $SubscriptionID,
        [parameter(Mandatory = $true)] 
        [String] $TenantID,
        [parameter(Mandatory = $true)] 
        [String] $ClientID,
        [parameter(Mandatory = $true)] 
        [String] $ClientSecret
    )

    $bearerToken = Get-Bearer -TenantID $TenantID -ClientID $ClientID -ClientSecret $ClientSecret

    $all = 0
    $ok = 0
    $LinkedServiceName.Split(',') | ForEach-Object { 
        $all += 1
        $ls = $_
        Write-Host "Testing ADF Linked Service connection: [$_] ..." 
        $r = Test-LinkedServiceConnection -LinkedServiceName $ls -DataFactoryName $DataFactoryName -ResourceGroup $ResourceGroupName -BearerToken $bearerToken
        if ($null -ne $r -and $r.succeeded) {
            Write-Host "[$_] : Connection successful."
            $ok += 1
        } else {
            Write-Host "[$_] : Connection failed."
        }
    }
    
    Write-Host "Test connection result:"
    Write-Host "Passed: $ok"
    Write-Host "Failed: $($all-$ok)"
    Write-Host "Total : $all"

}