Skip to content

Instantly share code, notes, and snippets.

@Sam-Martin
Last active April 16, 2016 15:17
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 Sam-Martin/f97c34491a2d5b58e2c0d5d3ff2b7415 to your computer and use it in GitHub Desktop.
Save Sam-Martin/f97c34491a2d5b58e2c0d5d3ff2b7415 to your computer and use it in GitHub Desktop.
An example of how to create a PowerShell based HTTP request based Azure Function
# Get input and output params (as named in our function.json)
$result = $Env:res
$requestPath = $env:req
$executionPath = Split-Path -parent $PSCommandPath
$tempPath = Split-Path -parent $env:req
# Read the input from file and parse it to an object
[Console]::WriteLine("Reading input from $env:req")
$requestObj = get-content $requestPath | out-string | convertfrom-json
# Manipulate our input a bit to create an output string
$output = "Hello {0} {1}" -f $requestObj.FirstName, $requestObj.LastName
# Let's try writing it to a file, because we can!
$filePath = "$env:temp\test.txt"
Set-Content $filePath -Value $output
[Console]::WriteLine("Reading data from $filePath `r`n`t'$(get-content $filePath)'")
# Finally let's output it
$output | Out-File -Encoding Ascii $result
@Sam-Martin
Copy link
Author

Example execution:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment