Skip to content

Instantly share code, notes, and snippets.

@RichieBzzzt
Last active January 25, 2019 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichieBzzzt/4497fddbee86399b1adb0599fb4c4d1c to your computer and use it in GitHub Desktop.
Save RichieBzzzt/4497fddbee86399b1adb0599fb4c4d1c to your computer and use it in GitHub Desktop.
$subscriptionId = ''
$resourceGroupName = ''
$factoryName = ''
$integrationRuntimeNames = @('', '')
$ErrorActionPreference = "Stop"
try{
Get-AzureRmSubscription -SubscriptionId $subscriptionId -ErrorVariable nosession
}
catch {}
if ($nosession) {
Write-Host "Obtaining access token..."
$rmAccount = Add-AzureRmAccount -SubscriptionId $subscriptionId
$tenantId = (Get-AzureRmSubscription -SubscriptionId $subscriptionId).TenantId
$tokenCache = $rmAccount.Context.TokenCache
$cachedTokens = $tokenCache.ReadItems() `
| Where-Object { $_.TenantId -eq $tenantId } `
| Sort-Object -Property ExpiresOn -Descending
$accessToken = $cachedTokens[0].AccessToken
}
foreach ($integrationRuntimeName in $integrationRuntimeNames) {
Write-Host "Syncing the credentials for IR $integrationRuntimeName on factory $factoryName"
$syncCredentials = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.DataFactory/factories/$factoryName/integrationRuntimes/$integrationRuntimeName/syncCredentials?api-version=2018-06-01"
Invoke-RestMethod -Method Post `
-Uri $syncCredentials `
-Headers @{ "Authorization" = "Bearer " + $accessToken }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment