File tree Expand file tree Collapse file tree
Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ function Invoke-PatchUser {
2+ <#
3+ . FUNCTIONALITY
4+ Entrypoint
5+ . ROLE
6+ Identity.User.ReadWrite
7+ #>
8+ [CmdletBinding ()]
9+ param ($Request , $TriggerMetadata )
10+
11+ $APIName = $Request.Params.CIPPEndpoint
12+ $Headers = $Request.Headers
13+ $tenantFilter = $Request.Body.tenantFilter
14+ Write-LogMessage - headers $Headers - API $APIName - message ' Accessed this API' - Sev ' Debug'
15+
16+ $HttpResponse = [HttpResponseContext ]@ {
17+ StatusCode = [HttpStatusCode ]::OK
18+ Body = @ {' Results' = @ (" Default response, you should never see this." ) }
19+ }
20+
21+ try {
22+ $UserObj = $Request.Body | Select-Object - Property * - ExcludeProperty tenantFilter
23+ if ([string ]::IsNullOrWhiteSpace($UserObj.id )) {
24+ $HttpResponse.StatusCode = [HttpStatusCode ]::BadRequest
25+ $HttpResponse.Body = @ {' Results' = @ (' Failed to patch user. No user ID provided' ) }
26+ } else {
27+ $UserObj
28+ $null = New-GraphPostRequest - uri " https://graph.microsoft.com/beta/users/$ ( $UserObj.id ) " - tenantid $tenantFilter - type PATCH - body $ ($UserObj | ConvertTo-Json ) - Verbose
29+ $HttpResponse.Body = @ {' Results' = @ (" Properties on user $ ( $UserObj.id ) patched successfully" ) }
30+ }
31+
32+ } catch {
33+ $HttpResponse.StatusCode = [HttpStatusCode ]::InternalServerError
34+ $HttpResponse.Body = @ {' Results' = @ (" Failed to patch user. Error: $ ( $_.Exception.Message ) " ) }
35+ }
36+
37+ Push-OutputBinding - Name Response - Value $HttpResponse
38+ }
You can’t perform that action at this time.
0 commit comments