Skip to content

Commit 5e63ff0

Browse files
Merge pull request KelvinTegelaar#1399 from kris6673/fix-intune-app-assignment
Fix: Intune app assignment
2 parents efd8d04 + a1b996b commit 5e63ff0

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/Applications/Invoke-ExecAssignApp.ps1

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ Function Invoke-ExecAssignApp {
1414
$Headers = $Request.Headers
1515
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

17-
18-
19-
2017
# Interact with query parameters or the body of the request.
21-
$tenantfilter = $Request.Query.TenantFilter
22-
$appFilter = $Request.Query.ID
23-
$AssignTo = $Request.Query.AssignTo
18+
$TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
19+
$appFilter = $Request.Query.ID ?? $Request.Body.ID
20+
$AssignTo = $Request.Query.AssignTo ?? $Request.Body.AssignTo
2421
$AssignBody = switch ($AssignTo) {
2522

2623
'AllUsers' {
@@ -42,20 +39,23 @@ Function Invoke-ExecAssignApp {
4239
}
4340

4441
}
45-
$body = [pscustomobject]@{'Results' = "$($TenantFilter): Assigned app to $assignTo" }
4642
try {
47-
$GraphRequest = New-Graphpostrequest -uri "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$appFilter/assign" -tenantid $TenantFilter -body $Assignbody
48-
Write-LogMessage -headers $Request.Headers -API $APINAME -tenant $($tenantfilter) -message "Assigned $($appFilter) to $assignTo" -Sev 'Info'
43+
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$appFilter/assign" -tenantid $TenantFilter -body $AssignBody
44+
$Result = "Successfully assigned app $($appFilter) to $($AssignTo)"
45+
Write-LogMessage -headers $Headers -API $APIName -tenant $($TenantFilter) -message $Result -Sev Info
46+
$StatusCode = [HttpStatusCode]::OK
4947

5048
} catch {
51-
Write-LogMessage -headers $Request.Headers -API $APINAME -tenant $($tenantfilter) -message "Failed to assign app $($appFilter): $($_.Exception.Message)" -Sev 'Error'
52-
$body = [pscustomobject]@{'Results' = "Failed to assign. $($_.Exception.Message)" }
49+
$ErrorMessage = Get-CippException -Exception $_
50+
$Result = "Failed to assign app $($appFilter) to $($AssignTo). Error: $($ErrorMessage.NormalizedError)"
51+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -Sev 'Error' -LogData $ErrorMessage
52+
$StatusCode = [HttpStatusCode]::InternalServerError
5353
}
5454

5555
# Associate values to output bindings by calling 'Push-OutputBinding'.
5656
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
57-
StatusCode = [HttpStatusCode]::OK
58-
Body = $body
57+
StatusCode = $StatusCode
58+
Body = @{ Results = $Result }
5959
})
6060

6161
}

0 commit comments

Comments
 (0)