Created
November 20, 2020 10:35
-
-
Save wsilveiranz/19f558a945305bfd185f9f13d3fb1115 to your computer and use it in GitHub Desktop.
What is my IP Powershell Function
This file contains hidden or 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
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." | |
$status = [HttpStatusCode]::OK | |
try { | |
$response = (Invoke-WebRequest -uri https://ifconfig.me/ip).Content | |
} | |
catch { | |
$status = [HttpStatusCode]::InternalServerError | |
$response = $_ | |
} | |
# Interact with query parameters or the body of the request. | |
# Associate values to output bindings by calling 'Push-OutputBinding'. | |
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | |
StatusCode = $status | |
Body = $response | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment