-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPLookup.ps1
More file actions
31 lines (25 loc) · 1.05 KB
/
Copy pathIPLookup.ps1
File metadata and controls
31 lines (25 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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."
# get IP only, strip all other columns, strip header
$Dyn_IP_siteA = Resolve-DnsName -Name siteA.domain.com -Type A -DnsOnly | Select IPAddress -ExpandProperty IPAddress
# Require a query parameter/value as a layer of abstraction/variability. This is not necessary but a) ensures anyone with your function URL has to know a parameter and its possible values, b) allows you to expand the function for multiple values.
$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}
if ($name -eq "Office1") {
$status = [HttpStatusCode]::OK
$body = $Dyn_IP_siteA
}
else {
$status = [HttpStatusCode]::BadRequest
$body = "Bad Request Logged"
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $status
Body = $body
})