Skip to content

Commit 34a7089

Browse files
committed
directory object lookup function
1 parent 2dec5a3 commit 34a7089

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
function Invoke-ListDirectoryObjects {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
.ROLE
6+
CIPP.Core.Read
7+
#>
8+
[CmdletBinding()]
9+
param($Request, $TriggerMetadata)
10+
11+
$APIName = $Request.Params.CIPPEndpoint
12+
$Headers = $Request.Headers
13+
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
14+
15+
$TenantFilter = $Request.Body.tenantFilter
16+
$AsApp = $Request.Body.asApp
17+
$Ids = $Request.Body.ids
18+
19+
$BaseUri = 'https://graph.microsoft.com/beta/directoryObjects/getByIds'
20+
if ($Request.Body.'$select') {
21+
$Uri = '{0}?$select={1}' -f $BaseUri, $Request.Body.'$select'
22+
} else {
23+
$Uri = $BaseUri
24+
}
25+
26+
$Body = @{
27+
ids = $Ids
28+
} | ConvertTo-Json -Depth 10
29+
30+
try {
31+
$Results = New-GraphPOSTRequest -tenantid $TenantFilter -uri $Uri -body $Body -AsApp $AsApp
32+
$StatusCode = [System.Net.HttpStatusCode]::OK
33+
} catch {
34+
$StatusCode = [System.Net.HttpStatusCode]::BadRequest
35+
$Results = $_.Exception.Message
36+
Write-Warning "Error retrieving directory objects: $Results"
37+
Write-Information $_.InvocationInfo.PositionMessage
38+
}
39+
40+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
41+
StatusCode = $StatusCode
42+
Body = $Results
43+
})
44+
}

0 commit comments

Comments
 (0)