@@ -15,36 +15,45 @@ Function Invoke-ExecDeviceAction {
15
15
Write-LogMessage - headers $Headers - API $APIName - message ' Accessed this API' - Sev ' Debug'
16
16
17
17
# 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
19
21
20
22
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 }
26
34
}
27
35
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
35
43
}
36
- $ActionResult = New-CIPPDeviceAction @cmdparams
44
+ $ActionResult = New-CIPPDeviceAction @cmdParams
37
45
38
- $body = [pscustomobject ]@ {' Results' = " $ActionResult " }
46
+ $StatusCode = [HttpStatusCode ]::OK
47
+ $Results = " $ActionResult "
39
48
40
49
} catch {
41
- $body = [pscustomobject ]@ {' Results' = " Failed to queue action $action on $DeviceFilter $ ( $_.Exception.Message ) " }
50
+ $StatusCode = [HttpStatusCode ]::InternalServerError
51
+ $Results = " $ ( $_.Exception.Message ) "
42
52
}
43
53
44
54
# Associate values to output bindings by calling 'Push-OutputBinding'.
45
55
Push-OutputBinding - Name Response - Value ([HttpResponseContext ]@ {
46
- StatusCode = [ HttpStatusCode ]::OK
47
- Body = $body
56
+ StatusCode = $StatusCode
57
+ Body = @ { ' Results ' = $Results }
48
58
})
49
-
50
59
}
0 commit comments