Last active
January 25, 2019 14:54
-
-
Save RichieBzzzt/4497fddbee86399b1adb0599fb4c4d1c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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