Skip to content

Instantly share code, notes, and snippets.

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 ArthurSteijn/25ef3df6e897688f25567c100dc43864 to your computer and use it in GitHub Desktop.
Save ArthurSteijn/25ef3df6e897688f25567c100dc43864 to your computer and use it in GitHub Desktop.
# 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
# Install needed python modules
python -m pip install pyodbc
# Get an access token with the Service Pricipal used in the Azure DevOps Pipeline
$access_token = (Get-AzAccessToken -ResourceUrl https://database.windows.net).Token
# Set Variables as example
$server_name = <myserver.database.windows.net>
$database_name = <mydatabase>
$query = <SELECT * FROM dbo.Table>
python.exe 'python-script-with-pyodbc.py' -server_name $server_name -access_token $access_token
#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