Skip to content

Commit

Permalink
Merge pull request KelvinTegelaar#370 from ashley-mspgeek/dev
Browse files Browse the repository at this point in the history
added functions for add/list/remove for scheduled tasks.
  • Loading branch information
KelvinTegelaar authored Jul 4, 2023
2 parents 79ebd25 + ae5241c commit bc451ef
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 0 deletions.
19 changes: 19 additions & 0 deletions AddScheduledItems/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"
}
]
}
18 changes: 18 additions & 0 deletions AddScheduledItems/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using namespace System.Net
param($Request, $TriggerMetadata)
$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$task = $Request.Body | ConvertFrom-Json
$Table = Get-CIPPTable -TableName 'ScheduledTasks'
Add-AzDataTableEntity @Table -Entity @{
PartitionKey = 'ScheduledTask'
RowKey = $task.TaskID
Command = $task.Command
Parameters = $task.Parameters
ScheduledTime = $task.ScheduledTime
# add more properties here based on what properties your tasks have
}
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = 'Task added successfully.'
})
19 changes: 19 additions & 0 deletions ListScheduledItems/junction.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"
}
]
}
15 changes: 15 additions & 0 deletions ListScheduledItems/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'
$Table = Get-CIPPTable -TableName 'ScheduledTasks'
$ScheduledTasks = Get-AzDataTableEntity @Table -Filter "PartitionKey eq 'ScheduledTask'"

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = @($ScheduledTasks)
})
19 changes: 19 additions & 0 deletions RemoveScheduledItems/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"
}
]
}
11 changes: 11 additions & 0 deletions RemoveScheduledItems/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using namespace System.Net
param($Request, $TriggerMetadata)
$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
$task = $Request.Body | ConvertFrom-Json
$Table = Get-CIPPTable -TableName 'ScheduledTasks'
Remove-AzDataTableEntity @Table -PartitionKey 'ScheduledTask' -RowKey $task.TaskID -force
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = 'Task removed successfully.'
})

0 comments on commit bc451ef

Please sign in to comment.