Skip to content

Commit 585e58f

Browse files
author
rvdwegen
committed
patch user endpoint
1 parent 7a63fe1 commit 585e58f

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

  • Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}

0 commit comments

Comments
 (0)