Created
October 31, 2019 20:51
-
-
Save DamolAAkinleye/307699f3d21934db4433eafa17be3f2f to your computer and use it in GitHub Desktop.
Created with Copy to Gist
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
96 | |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | |
104 | |
105 | |
106 | |
107 | |
108 | |
# This scripts pauses your Integration Runtime (and its trigger) if it is running | |
# Parameters | |
$ConnectionName = 'AzureRunAsConnection' | |
$DataFactoryName = 'ADF-SSISJoost' | |
$ResourceGroup = 'joost_van_rossum' | |
$TriggerName = 'Hourly' | |
# Do not continue after an error | |
$ErrorActionPreference = "Stop" | |
######################################################## | |
# Log in to Azure (standard code) | |
######################################################## | |
Write-Verbose -Message 'Connecting to Azure' | |
try | |
{ | |
# Get the connection "AzureRunAsConnection " | |
$ServicePrincipalConnection = Get-AutomationConnection -Name $ConnectionName | |
'Log in to Azure...' | |
$null = Add-AzureRmAccount ` | |
-ServicePrincipal ` | |
-TenantId $ServicePrincipalConnection.TenantId ` | |
-ApplicationId $ServicePrincipalConnection.ApplicationId ` | |
-CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint | |
} | |
catch | |
{ | |
if (!$ServicePrincipalConnection) | |
{ | |
# You forgot to turn on 'Create Azure Run As account' | |
$ErrorMessage = "Connection $ConnectionName not found." | |
throw $ErrorMessage | |
} | |
else | |
{ | |
# Something went wrong | |
Write-Error -Message $_.Exception.Message | |
throw $_.Exception | |
} | |
} | |
######################################################## | |
# Get Integration Runtime in Azure Data Factory | |
$IntegrationRuntime = Get-AzureRmDataFactoryV2IntegrationRuntime ` | |
-DataFactoryName $DataFactoryName ` | |
-ResourceGroupName $ResourceGroup | |
# Check if Integration Runtime was found | |
if (!$IntegrationRuntime) | |
{ | |
# Your ADF does not have a Integration Runtime | |
# or the ADF does not exist | |
$ErrorMessage = "No Integration Runtime found in ADF $($DataFactoryName)." | |
throw $ErrorMessage | |
} | |
# Check if the Integration Runtime is running | |
elseif ($IntegrationRuntime.State -eq "Started") | |
{ | |
<# Start Trigger Deactivation #> | |
# Getting trigger to check if it exists | |
$Trigger = Get-AzureRmDataFactoryV2Trigger ` | |
-DataFactoryName $DataFactoryName ` | |
-Name $TriggerName ` | |
-ResourceGroupName $ResourceGroup | |
# Check if the trigger was found | |
if (!$Trigger) | |
{ | |
# Fail options: | |
# The ADF does not exist (typo) | |
# The trigger does not exist (typo) | |
$ErrorMessage = "Trigger $($TriggerName) not found." | |
throw $ErrorMessage | |
} | |
# Check if the trigger is activated | |
elseif ($Trigger.RuntimeState -eq "Started") | |
{ | |
Write-Output "Stopping Trigger $($TriggerName)" | |
$null = Stop-AzureRmDataFactoryV2Trigger ` | |
-DataFactoryName $DataFactoryName ` | |
-Name $TriggerName ` | |
-ResourceGroupName $ResourceGroup ` | |
-Force | |
} | |
else | |
{ | |
# Write message to screen (not throwing error) | |
Write-Output "Trigger $($TriggerName) is not activated." | |
} | |
<# End Trigger Deactivation #> | |
# Stop the integration runtime | |
Write-Output "Pausing Integration Runtime $($IntegrationRuntime.Name)." | |
$null = Stop-AzureRmDataFactoryV2IntegrationRuntime ` | |
-DataFactoryName $IntegrationRuntime.DataFactoryName ` | |
-Name $IntegrationRuntime.Name ` | |
-ResourceGroupName $IntegrationRuntime.ResourceGroupName ` | |
-Force | |
Write-Output "Done" | |
} | |
else | |
{ | |
# Write message to screen (not throwing error) | |
Write-Output "Integration Runtime $($IntegrationRuntime.Name) is not running." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment