Created
February 5, 2022 15:12
-
-
Save ArthurSteijn/e954f9c96dd796b7c323f9c6b46b8def 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
# Azure PowerShell | |
# https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-powershell?view=azure-devops | |
# Run a PowerShell script within an Azure environment | |
- task: AzurePowerShell@5 | |
inputs: | |
azureSubscription: <YourServiceConnection> # Required. Name of Azure Resource Manager service connection | |
scriptType: 'inlineScript' # Optional. Options: filePath, inlineScript | |
#scriptPath: # Optional | |
inline: | # '# You can write your Azure PowerShell scripts inline here. # You can also pass predefined and custom variables to this script using arguments' # Optional | |
# Import needed modules | |
Import-Module SQLServer | |
Import-Module Az.Accounts -MinimumVersion 2.2.0 | |
# Get an access token with the Service Pricipal used in the Azure DevOps Pipeline | |
$access_token = (Get-AzAccessToken -ResourceUrl https://database.windows.net).Token | |
$ServerInstance = <myserver.database.windows.net> | |
$database_name = <mydatabase> | |
$query = <SELECT * FROM dbo.Table> | |
# Execute the query on the SQL Serverless instance | |
Invoke-Sqlcmd -ServerInstance $ServerInstance -Database $currentcon -AccessToken $access_token -query $query | |
#scriptArguments: # Optional | |
#errorActionPreference: 'stop' # Optional. Options: stop, continue, silentlyContinue | |
#failOnStandardError: false # Optional | |
azurePowerShellVersion: 'latestVersion' # Required. Options: latestVersion, otherVersion | |
#preferredAzurePowerShellVersion: # Required when azurePowerShellVersion == OtherVersion | |
#pwsh: true # Optional. If true, then will use PowerShell Core pwsh.exe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment