Skip to content

Instantly share code, notes, and snippets.

View ArthurSteijn's full-sized avatar

Arthur Stejin ArthurSteijn

  • HSO
  • Rotterdam, the Netherlands
  • 19:51 (UTC +02:00)
View GitHub Profile
# 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
# 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 pyodbc
import struct
def use_token(server_name, access_token):
connection_string = 'Driver={ODBC Driver 17 for SQL Server};server='+server_name+';database=master;'
SQL_COPT_SS_ACCESS_TOKEN = 1256
exptoken = b''
for i in bytes(access_token, "UTF-8"):
exptoken += bytes({i})
import requests
def send_error_to_teams(error_message, webhook_url):
""" This function will use the requests library to make a POST request to the webhook URL with the error message as the payload """
payload = {
"text": error_message
}
response = requests.post(webhook_url, json=payload)
response.raise_for_status()
WEBHOOK_URL = "your_teams_webhook_url"
@send_error_to_teams_decorator(WEBHOOK_URL)
def my_function():
try:
raise Exception("This try block always fails!")
except Exception as e:
raise ValueError(f"ValueError: {str(e)}")
my_function()