@@ -227,6 +227,113 @@ function Invoke-ExecCustomData {
227
227
}
228
228
}
229
229
}
230
+ ' ListDirectoryExtensions' {
231
+ try {
232
+ $Uri = " https://graph.microsoft.com/beta/applications(appId='$ ( $env: ApplicationId ) ')/extensionProperties"
233
+ $DirectoryExtensions = New-GraphGetRequest - uri $Uri - AsApp $true - NoAuthCheck $true - tenantid $env: TenantID
234
+
235
+ $Body = @ {
236
+ Results = @ ($DirectoryExtensions )
237
+ }
238
+ } catch {
239
+ $Body = @ {
240
+ Results = @ (
241
+ @ {
242
+ state = ' error'
243
+ resultText = " Failed to retrieve directory extensions: $ ( $_.Exception.Message ) "
244
+ }
245
+ )
246
+ }
247
+ }
248
+ }
249
+ ' AddDirectoryExtension' {
250
+ try {
251
+ $ExtensionName = $Request.Body.name
252
+ $DataType = $Request.Body.dataType
253
+ $TargetObjects = $Request.Body.targetObjects
254
+ $IsMultiValued = $Request.Body.isMultiValued -eq $true
255
+
256
+ if (! $ExtensionName -or ! $DataType -or ! $TargetObjects ) {
257
+ throw ' Extension name, data type, and target objects are required.'
258
+ }
259
+
260
+ $AppId = $env: ApplicationId # Replace with your application ID
261
+ $Uri = " https://graph.microsoft.com/beta/applications(appId='$AppId ')/extensionProperties"
262
+
263
+ $BodyContent = @ {
264
+ name = $ExtensionName
265
+ dataType = $DataType
266
+ targetObjects = $TargetObjects
267
+ isMultiValued = $IsMultiValued
268
+ } | ConvertTo-Json - Depth 5 - Compress
269
+
270
+ $Response = New-GraphPOSTRequest - Uri $Uri - Body $BodyContent - AsApp $true - NoAuthCheck $true - tenantid $env: TenantID
271
+
272
+ $Body = @ {
273
+ Results = @ {
274
+ state = ' success'
275
+ resultText = " Directory extension '$ExtensionName ' added successfully."
276
+ extension = $Response
277
+ }
278
+ }
279
+
280
+ # store the extension in the custom data table
281
+ $Entity = @ {
282
+ PartitionKey = ' DirectoryExtension'
283
+ RowKey = $Response.name
284
+ JSON = [string ](ConvertFrom-Json $Response - Compress - Depth 5 )
285
+ }
286
+ } catch {
287
+ $Body = @ {
288
+ Results = @ (
289
+ @ {
290
+ state = ' error'
291
+ resultText = " Failed to add directory extension: $ ( $_.Exception.Message ) "
292
+ }
293
+ )
294
+ }
295
+ }
296
+ }
297
+ ' DeleteDirectoryExtension' {
298
+ try {
299
+ $ExtensionName = $Request.Body.name
300
+ $ExtensionId = $Request.Body.id
301
+ if (! $ExtensionName ) {
302
+ throw ' Extension name is missing in the request body.'
303
+ }
304
+ $AppId = $env: ApplicationId # Replace with your application ID
305
+ $Uri = " https://graph.microsoft.com/beta/applications(appId='$AppId ')/extensionProperties/$ExtensionId "
306
+
307
+ # Delete the directory extension from Microsoft Graph
308
+ $null = New-GraphPOSTRequest - Type DELETE - Uri $Uri - AsApp $true - NoAuthCheck $true - tenantid $env: TenantID
309
+ try {
310
+ $CustomDataTable = Get-CippTable - TableName ' CustomData'
311
+ $ExtensionEntity = Get-CIPPAzDataTableEntity @CustomDataTable - Filter " PartitionKey eq 'DirectoryExtension' and RowKey eq '$ExtensionName '"
312
+ # Remove the extension from the custom data table
313
+ if ($ExtensionEntity ) {
314
+ Remove-AzDataTableEntity @CustomDataTable - Entity $ExtensionEntity
315
+ }
316
+ } catch {
317
+ Write-Warning " Failed to delete directory extension from custom data table: $ ( $_.Exception.Message ) "
318
+ }
319
+
320
+ $Body = @ {
321
+ Results = @ {
322
+ state = ' success'
323
+ resultText = " Directory extension '$ExtensionName ' deleted successfully."
324
+ }
325
+ }
326
+ } catch {
327
+ $Body = @ {
328
+ Results = @ (
329
+ @ {
330
+ state = ' error'
331
+ resultText = " Failed to delete directory extension: $ ( $_.Exception.Message ) "
332
+ }
333
+ )
334
+ }
335
+ }
336
+ }
230
337
default {
231
338
$Body = @ {
232
339
Results = @ (
0 commit comments