Skip to content

Commit

Permalink
NEW FEATURE: Templating engine intune
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Nov 7, 2021
1 parent 3660710 commit 940f6a1
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 15 deletions.
File renamed without changes.
40 changes: 40 additions & 0 deletions AddIntuneTemplate/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"



try {
if (!$Request.body.displayname) { throw "You must enter a displayname" }
if (!$Request.body.rawjson) { throw "You must fill in the RAW json" }
if ($null -eq ($Request.body.Rawjson | ConvertFrom-Json)) { throw "the JSON is invalid" }
$GUID = New-Guid

$object = [PSCustomObject]@{
Displayname = $request.body.displayname
Description = $request.body.description
RAWJson = $request.body.RawJSON
Type = $request.body.TemplateType
GUID = $GUID
} | ConvertTo-Json
New-Item Config -ItemType Directory -ErrorAction SilentlyContinue
Set-Content "Config\$($GUID).IntuneTemplate.json" -Value $Object -Force
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created intune policy template named $($Request.body.displayname) with GUID $GUID" -Sev "Debug"

$body = [pscustomobject]@{"Results" = "Successfully added template" }
}
catch {
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Intune Template Deployment failed: $($_.Exception.Message)" -Sev "Error"
$body = [pscustomobject]@{"Results" = "Intune Template Deployment failed: $($_.Exception.Message)" }
}


# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
19 changes: 19 additions & 0 deletions ListIntuneTemplates/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
]
}
22 changes: 7 additions & 15 deletions AddApp/run.ps1 → ListIntuneTemplates/run.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using namespace System.Net
using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
Expand All @@ -9,21 +9,13 @@ Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -messa

# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
Write-Host $Request.query.id
$Templates = Get-ChildItem "Config\*.IntuneTemplate.json" | ForEach-Object { Get-Content $_ | ConvertFrom-Json }
if ($Request.query.ID) { $Templates = $Templates | Where-Object -Property guid -EQ $Request.query.id }

# 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."

if ($name) {
$body = "Hello, $name. This HTTP triggered function executed successfully."
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
StatusCode = [HttpStatusCode]::OK
Body = @($Templates)
})
19 changes: 19 additions & 0 deletions RemoveIntuneTemplate/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
]
}
26 changes: 26 additions & 0 deletions RemoveIntuneTemplate/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"

$ID = $request.query.id
try {
Remove-Item "Config\$($ID).IntuneTemplate.json" -Force
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Removed Intune Template with ID $ID." -Sev "Info"
$body = [pscustomobject]@{"Results" = "Successfully removed Intune Template" }
}
catch {
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Failed to remove intune template $ID. $($_.Exception.Message)" -Sev "Error"
$body = [pscustomobject]@{"Results" = "Failed to remove template" }
}


# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})

0 comments on commit 940f6a1

Please sign in to comment.