diff --git a/RemoveApp/function.json b/RemoveApp/function.json new file mode 100644 index 000000000000..306b0c51e560 --- /dev/null +++ b/RemoveApp/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/RemoveApp/run.ps1 b/RemoveApp/run.ps1 new file mode 100644 index 000000000000..cabd77dddb41 --- /dev/null +++ b/RemoveApp/run.ps1 @@ -0,0 +1,31 @@ +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" + +# Interact with query parameters or the body of the request. +$TenantFilter = $Request.Query.TenantFilter +$policyId = $Request.Query.ID +if (!$policyId) { exit } +try { + #$unAssignRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/deviceManagement/configurationPolicies('$($policyId)')/assign" -type POST -Body '{"assignments":[]}' -tenant $TenantFilter + $GraphRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$($policyId)" -type DELETE -tenant $TenantFilter + Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Deleted $policyId" -Sev "Info" -tenant $TenantFilter + $body = [pscustomobject]@{"Results" = "Succesfully deleted the application" } +} +catch { + Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Could not delete app $policyId. $($_.Exception.Message)" -Sev "Error" -tenant $TenantFilter + $body = [pscustomobject]@{"Results" = "Could not delete this application: $($_.Exception.Message)" } + +} + +# Associate values to output bindings by calling 'Push-OutputBinding'. +Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ + StatusCode = [HttpStatusCode]::OK + Body = $body + }) + +#@{ Name = 'LicJoined'; Expression = { ($_.assignedLicenses | ForEach-Object { convert-skuname -skuID $_.skuid }) -join ", " } }, @{ Name = 'Aliases'; Expression = { $_.Proxyaddresses -join ", " } }, @{ Name = 'primDomain'; Expression = { $_.userPrincipalName -split "@" | Select-Object -Last 1 } } \ No newline at end of file