@@ -15,36 +15,45 @@ Function Invoke-ExecDeviceAction {
1515 Write-LogMessage - headers $Headers - API $APIName - message ' Accessed this API' - Sev ' Debug'
1616
1717 # Interact with Body parameters or the body of the request.
18-
18+ $Action = $Request.Body.Action
19+ $DeviceFilter = $Request.Body.GUID
20+ $TenantFilter = $Request.Body.tenantFilter
1921
2022 try {
21- if ($Request.Body.Action -eq ' setDeviceName' ) {
22- $ActionBody = @ { deviceName = $Request.Body.input } | ConvertTo-Json - Compress
23- }
24- else {
25- $ActionBody = $Request.Body | ConvertTo-Json - Compress
23+ switch ($Action ) {
24+ ' setDeviceName' {
25+ $ActionBody = @ { deviceName = $Request.Body.input } | ConvertTo-Json - Compress
26+ break
27+ }
28+ ' users' {
29+ $ActionBody = @ { ' @odata.id' = " https://graph.microsoft.com/beta/users('$ ( $Request.Body.user.value ) ')" } | ConvertTo-Json - Compress
30+ Write-Host " ActionBody: $ActionBody "
31+ break
32+ }
33+ Default { $ActionBody = $Request.Body | ConvertTo-Json - Compress }
2634 }
2735
28- $cmdparams = @ {
29- Action = $Request .Body. Action
30- ActionBody = $ActionBody
31- DeviceFilter = $Request .Body.GUID
32- TenantFilter = $Request .Body. TenantFilter
33- Headers = $Request . Headers
34- APINAME = $APINAME
36+ $cmdParams = @ {
37+ Action = $Action
38+ ActionBody = $ActionBody
39+ DeviceFilter = $DeviceFilter
40+ TenantFilter = $TenantFilter
41+ Headers = $Headers
42+ APINAME = $APIName
3543 }
36- $ActionResult = New-CIPPDeviceAction @cmdparams
44+ $ActionResult = New-CIPPDeviceAction @cmdParams
3745
38- $body = [pscustomobject ]@ {' Results' = " $ActionResult " }
46+ $StatusCode = [HttpStatusCode ]::OK
47+ $Results = " $ActionResult "
3948
4049 } catch {
41- $body = [pscustomobject ]@ {' Results' = " Failed to queue action $action on $DeviceFilter $ ( $_.Exception.Message ) " }
50+ $StatusCode = [HttpStatusCode ]::InternalServerError
51+ $Results = " $ ( $_.Exception.Message ) "
4252 }
4353
4454 # Associate values to output bindings by calling 'Push-OutputBinding'.
4555 Push-OutputBinding - Name Response - Value ([HttpResponseContext ]@ {
46- StatusCode = [ HttpStatusCode ]::OK
47- Body = $body
56+ StatusCode = $StatusCode
57+ Body = @ { ' Results ' = $Results }
4858 })
49-
5059}
0 commit comments