Skip to content

Instantly share code, notes, and snippets.

@SQLvariant
Created July 15, 2022 20:14
Show Gist options
  • Save SQLvariant/e2eee30ccac6316af431e5d7760883de to your computer and use it in GitHub Desktop.
Save SQLvariant/e2eee30ccac6316af431e5d7760883de to your computer and use it in GitHub Desktop.
PowerShell script to read info out of Linked Services .JSON files on your local machine.
# > Before you begin, navigate to a local directory containing the Linked Services files from your ADF
c:\temp\ADF\linkedService
# First, run through all of the ADF LinkedService files to extract all the pieces of the connection information we're loking for.
$LinkedServices = @()
$LinkedServiceFiles = dir -Filter *.json
foreach($LinkedServiceFile in $LinkedServiceFiles){
$LinkedServiceContents = Get-Content -Path $LinkedServiceFile | ConvertFrom-Json -Depth 20
switch($LinkedServiceContents.properties.type){
'AzureSqlDatabase' {$Connection = $LinkedServiceContents.properties.typeProperties.connectionString}
'AzureSqlDW' {$Connection = $LinkedServiceContents.properties.typeProperties.connectionString}
'AzureDataExplorer' {$Connection = $LinkedServiceContents.properties.typeProperties.endpoint }
'AzureBlobFS' {$Connection = $LinkedServiceContents.properties.typeProperties.url}
'HttpServer' {$Connection = $LinkedServiceContents.properties.typeProperties.url}
'AzureKeyVault' {$Connection = $LinkedServiceContents.properties.typeProperties.baseUrl}
'AzureDataLakeStore' {$Connection = $LinkedServiceContents.properties.typeProperties.dataLakeStoreUri}
}
switch($LinkedServiceContents.properties.type){
'AzureSqlDatabase' {$Database = $LinkedServiceContents.properties.typeProperties.connectionString.Split(';')[4] -replace 'Initial Catalog=', ''}
'AzureSqlDW' {$Database = $LinkedServiceContents.properties.typeProperties.connectionString.Split(';')[4] -replace 'Initial Catalog=', ''}
'AzureDataExplorer' {$Database = $LinkedServiceContents.properties.typeProperties.database }
}
$LinkedServices += $LinkedServiceContents | SELECT @{label='Type';expression ={$_.properties.type}},
Name,
@{label='Connection';expression ={$Connection}},
@{label='Database';expression ={$Database}},
@{label='tenant';expression ={$_.properties.typeProperties.tenant}},
@{label='servicePrincipalId';expression ={$_.properties.typeProperties.servicePrincipalId}},
@{label='servicePrincipalKey';expression ={$_.properties.typeProperties.servicePrincipalKey}},
@{label='typeProperties';expression ={$_.properties.typeProperties}}
#@{label='endpoint';expression ={$_.properties.typeProperties.endpoint}},
#@{label='connectionString';expression ={$_.properties.typeProperties.connectionString}},
#@{label='url';expression ={$_.properties.typeProperties.url}},
#@{label='baseUrl';expression ={$_.properties.typeProperties.baseUrl}},
#@{label='dataLakeStoreUri';expression ={$_.properties.typeProperties.dataLakeStoreUri}},
#@{label='database';expression ={$_.properties.typeProperties.database}},
$LinkedServiceFile = $null
$Connection = $null
$Database = $null
}
$LinkedServices |
sort Type |
ft -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment