Skip to content

Commit

Permalink
Merge pull request KelvinTegelaar#374 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
Hotfix to release
  • Loading branch information
KelvinTegelaar authored Jul 6, 2023
2 parents 3846c79 + af607fc commit 43b4591
Show file tree
Hide file tree
Showing 22 changed files with 168 additions and 4 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"
}
]
}
20 changes: 20 additions & 0 deletions AddScheduledItems/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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'
TaskState = 'Scheduled'
RowKey = $task.TaskID
Command = $task.Command
Parameters = $task.Parameters
ScheduledTime = $task.ScheduledTime
Results = 'Not Executed'
# add more properties here based on what properties your tasks have
}
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = 'Task added successfully.'
})
2 changes: 1 addition & 1 deletion BestPracticeAnalyser_All/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ try {
$Result.TAPEnabled = $TAPEnabled.State
}
catch {
Write-LogMessage -API 'BestPracticeAnalyser' -tenant $tenant -message "Security Defaults State on $($tenant) Error: $($_.exception.message)" -sev 'Error'
Write-LogMessage -API 'BestPracticeAnalyser' -tenant $tenant -message "Retrieving TAP state failed: $($tenant) Error: $($_.exception.message)" -sev 'Error'
}
# Get the nudge State
try {
Expand Down
2 changes: 2 additions & 0 deletions Cache_SAMSetup/SAMManifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
{ "id": "45cc0394-e837-488b-a098-1918f48d186c", "type": "Role" },
{ "id": "be74164b-cff1-491c-8741-e671cb536e13", "type": "Role" },
{ "id": "2a60023f-3219-47ad-baa4-40e17cd02a1d", "type": "Role" },
{ "id": "338163d7-f101-4c92-94ba-ca46fe52447c", "type": "Role" },
{ "id": "cac88765-0581-4025-9725-5ebc13f729ee", "type": "Role" },
{ "id": "b27a61ec-b99c-4d6a-b126-c4375d08ae30", "type": "Scope" },
{ "id": "84bccea3-f856-4a8a-967b-dbe0a3d53a64", "type": "Scope" },
{ "id": "280b3b69-0437-44b1-bc20-3b2fca1ee3e9", "type": "Scope" },
Expand Down
19 changes: 19 additions & 0 deletions ListScheduledItems/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"
}
]
}
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)
})
2 changes: 1 addition & 1 deletion Modules/GraphRequests/Public/Get-GraphRequestList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function Get-GraphRequestList {
$GraphRequestResults = New-GraphGetRequest @GraphRequest -ErrorAction Stop
if ($ReverseTenantLookup -and $GraphRequestResults) {
$TenantInfo = $GraphRequestResults.$ReverseTenantLookupProperty | Sort-Object -Unique | ForEach-Object {
New-GraphGetRequest -uri "https://graph.microsoft.com/beta/tenantRelationships/findTenantInformationByTenantId(tenantId='$_')" -noauthcheck $true -asApp:$true
New-GraphGetRequest -uri "https://graph.microsoft.com/beta/tenantRelationships/findTenantInformationByTenantId(tenantId='$_')" -noauthcheck $true -asApp:$true -tenant $env:TenantId
}
foreach ($Result in $GraphRequestResults) {
$Result | Select-Object @{n = 'TenantInfo'; e = { $TenantInfo | Where-Object { $Result.$ReverseTenantLookupProperty -eq $_.tenantId } } }, *
Expand Down
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.'
})
15 changes: 15 additions & 0 deletions Scheduler_UserTasks/_functions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"bindings": [
{
"name": "Timer",
"schedule": "0 */15 * * * *",
"direction": "in",
"type": "timerTrigger"
},
{
"name": "starter",
"type": "durableClient",
"direction": "in"
}
]
}
44 changes: 44 additions & 0 deletions Scheduler_UserTasks/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
param($Timer)

$Table = Get-CippTable -tablename 'ScheduledTasks'
$Filter = "Results eq 'Not Executed'"
$tasks = Get-AzDataTableEntity @Table -Filter $Filter

foreach ($task in $tasks) {
# Check if task has not been executed yet (i.e., 'Results' is 'Not Executed')
if ((Get-Date) -ge $task.ExpectedRunTime) {
try {
Update-AzDataTableEntity @Table -Entity @{
PartitionKey = $task.PartitionKey
RowKey = $task.RowKey
TaskState = 'Running'
# Update other properties as needed
}

$results = Invoke-Command -ScriptBlock ([ScriptBlock]::Create($task.Command)) -ArgumentList $task.Parameters

Update-AzDataTableEntity @Table -Entity @{
PartitionKey = $task.PartitionKey
RowKey = $task.RowKey
Results = "$results"
TaskState = 'Completed'
# Update other properties as needed
}

Write-LogMessage -API "Scheduler_UserTasks" -tenant $tenant -message "Successfully executed task: $($task.RowKey)" -sev Info
}
catch {
$errorMessage = $_.Exception.Message

Update-AzDataTableEntity @Table -Entity @{
PartitionKey = $task.PartitionKey
RowKey = $task.RowKey
Results = "$errorMessage"
TaskState = 'Failed'
# Update other properties as needed
}

Write-LogMessage -API "Scheduler_UserTasks" -tenant $tenant -message "Failed to execute task: $errorMessage" -sev Error
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ foreach ($Template in $Setting.TemplateList) {
catch {
Write-LogMessage -API "Standards" -tenant $tenant -message "Failed to create or update Intune Template: $($_.exception.message)" -sev "Error"
}
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion version_latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.1
3.7.2

0 comments on commit 43b4591

Please sign in to comment.