Skip to content

Instantly share code, notes, and snippets.

@sjorspa
Created October 14, 2023 09:41
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 sjorspa/4ca19c817a648de4e1a2dd0cda1e43f4 to your computer and use it in GitHub Desktop.
Save sjorspa/4ca19c817a648de4e1a2dd0cda1e43f4 to your computer and use it in GitHub Desktop.
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}
$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
$result
try{
$token = (Get-AzAccessToken -ResourceUrl https://database.windows.net).Token
Invoke-SqlCmd -ServerInstance "mysupersql.database.windows.net" `
-Database "testconn" `
-AccessToken "$token" `
-ConnectionTimeOut 10 `
-Query "select 2"
$result = 'ok'
}
catch{
Write-Host $_.Exception.Message
$result = $Error[0]
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $result
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment