diff --git a/AddScheduledItems/function.json b/AddScheduledItems/function.json new file mode 100644 index 0000000000000..925eab5aeae1e --- /dev/null +++ b/AddScheduledItems/function.json @@ -0,0 +1,19 @@ +{ + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "Request", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "Response" + } + ] + } \ No newline at end of file diff --git a/AddScheduledItems/run.ps1 b/AddScheduledItems/run.ps1 new file mode 100644 index 0000000000000..b8dbc7843324d --- /dev/null +++ b/AddScheduledItems/run.ps1 @@ -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.' +}) \ No newline at end of file diff --git a/BestPracticeAnalyser_All/run.ps1 b/BestPracticeAnalyser_All/run.ps1 index 08003efa32afb..741da28b8eaa1 100644 --- a/BestPracticeAnalyser_All/run.ps1 +++ b/BestPracticeAnalyser_All/run.ps1 @@ -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 { diff --git a/Cache_SAMSetup/SAMManifest.json b/Cache_SAMSetup/SAMManifest.json index d91d319312e0d..3f458048fda0a 100644 --- a/Cache_SAMSetup/SAMManifest.json +++ b/Cache_SAMSetup/SAMManifest.json @@ -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" }, diff --git a/ListScheduledItems/function.json b/ListScheduledItems/function.json new file mode 100644 index 0000000000000..b0ca1676cc0bc --- /dev/null +++ b/ListScheduledItems/function.json @@ -0,0 +1,19 @@ +{ + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "Request", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "Response" + } + ] + } \ No newline at end of file diff --git a/ListScheduledItems/run.ps1 b/ListScheduledItems/run.ps1 new file mode 100644 index 0000000000000..3b76fb77b2125 --- /dev/null +++ b/ListScheduledItems/run.ps1 @@ -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) + }) \ No newline at end of file diff --git a/Modules/GraphRequests/Public/Get-GraphRequestList.ps1 b/Modules/GraphRequests/Public/Get-GraphRequestList.ps1 index 7793fed428e51..59873b095b449 100644 --- a/Modules/GraphRequests/Public/Get-GraphRequestList.ps1 +++ b/Modules/GraphRequests/Public/Get-GraphRequestList.ps1 @@ -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 } } }, * diff --git a/RemoveScheduledItems/function.json b/RemoveScheduledItems/function.json new file mode 100644 index 0000000000000..925eab5aeae1e --- /dev/null +++ b/RemoveScheduledItems/function.json @@ -0,0 +1,19 @@ +{ + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "Request", + "methods": [ + "get", + "post" + ] + }, + { + "type": "http", + "direction": "out", + "name": "Response" + } + ] + } \ No newline at end of file diff --git a/RemoveScheduledItems/run.ps1 b/RemoveScheduledItems/run.ps1 new file mode 100644 index 0000000000000..ce7c0a0dcd9ca --- /dev/null +++ b/RemoveScheduledItems/run.ps1 @@ -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.' +}) \ No newline at end of file diff --git a/Scheduler_UserTasks/_functions.json b/Scheduler_UserTasks/_functions.json new file mode 100644 index 0000000000000..a4e981dd588d6 --- /dev/null +++ b/Scheduler_UserTasks/_functions.json @@ -0,0 +1,15 @@ +{ + "bindings": [ + { + "name": "Timer", + "schedule": "0 */15 * * * *", + "direction": "in", + "type": "timerTrigger" + }, + { + "name": "starter", + "type": "durableClient", + "direction": "in" + } + ] + } \ No newline at end of file diff --git a/Scheduler_UserTasks/run.ps1 b/Scheduler_UserTasks/run.ps1 new file mode 100644 index 0000000000000..91432822b6024 --- /dev/null +++ b/Scheduler_UserTasks/run.ps1 @@ -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 + } + } +} \ No newline at end of file diff --git a/standards_ConditionalAccess/function.json b/Standards_ConditionalAccess/function.json similarity index 100% rename from standards_ConditionalAccess/function.json rename to Standards_ConditionalAccess/function.json diff --git a/standards_ConditionalAccess/run.ps1 b/Standards_ConditionalAccess/run.ps1 similarity index 100% rename from standards_ConditionalAccess/run.ps1 rename to Standards_ConditionalAccess/run.ps1 diff --git a/standards_ExConnector/function.json b/Standards_ExConnector/function.json similarity index 100% rename from standards_ExConnector/function.json rename to Standards_ExConnector/function.json diff --git a/standards_ExConnector/run.ps1 b/Standards_ExConnector/run.ps1 similarity index 100% rename from standards_ExConnector/run.ps1 rename to Standards_ExConnector/run.ps1 diff --git a/standards_GroupTemplate/function.json b/Standards_GroupTemplate/function.json similarity index 100% rename from standards_GroupTemplate/function.json rename to Standards_GroupTemplate/function.json diff --git a/standards_GroupTemplate/run.ps1 b/Standards_GroupTemplate/run.ps1 similarity index 100% rename from standards_GroupTemplate/run.ps1 rename to Standards_GroupTemplate/run.ps1 diff --git a/standards_IntuneTemplate/function.json b/Standards_IntuneTemplate/function.json similarity index 100% rename from standards_IntuneTemplate/function.json rename to Standards_IntuneTemplate/function.json diff --git a/standards_IntuneTemplate/run.ps1 b/Standards_IntuneTemplate/run.ps1 similarity index 99% rename from standards_IntuneTemplate/run.ps1 rename to Standards_IntuneTemplate/run.ps1 index 9ead260460c6e..1db59ef6e28e8 100644 --- a/standards_IntuneTemplate/run.ps1 +++ b/Standards_IntuneTemplate/run.ps1 @@ -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" } -} \ No newline at end of file +} diff --git a/standards_TransportRuleTemplate/function.json b/Standards_TransportRuleTemplate/function.json similarity index 100% rename from standards_TransportRuleTemplate/function.json rename to Standards_TransportRuleTemplate/function.json diff --git a/standards_TransportRuleTemplate/run.ps1 b/Standards_TransportRuleTemplate/run.ps1 similarity index 100% rename from standards_TransportRuleTemplate/run.ps1 rename to Standards_TransportRuleTemplate/run.ps1 diff --git a/version_latest.txt b/version_latest.txt index 5cdb444f3d417..47b6be3fafeca 100644 --- a/version_latest.txt +++ b/version_latest.txt @@ -1 +1 @@ -3.7.1 \ No newline at end of file +3.7.2 \ No newline at end of file