@@ -156,12 +156,13 @@ function Get-TargetResource
156
156
$nullReturn = $PSBoundParameters
157
157
$nullReturn.Ensure = ' Absent'
158
158
159
+ $AADServicePrincipal = $null
159
160
try
160
161
{
161
162
if (-not [System.String ]::IsNullOrEmpty($ObjectID ))
162
163
{
163
164
$AADServicePrincipal = Get-MgServicePrincipal - ServicePrincipalId $ObjectId `
164
- - Property $Script :PropertiesToExport
165
+ - Property $Script :PropertiesToExport `
165
166
- Expand ' AppRoleAssignedTo' `
166
167
- ErrorAction Stop
167
168
}
@@ -176,12 +177,12 @@ function Get-TargetResource
176
177
$ObjectGuid = [System.Guid ]::empty
177
178
if (-not [System.Guid ]::TryParse($AppId , [System.Management.Automation.PSReference ]$ObjectGuid ))
178
179
{
179
- $appInstance = Get-MgApplication - Filter " DisplayName eq '$ ( $AppId -replace " '" , " ''" ) '"
180
- if ($appInstance )
181
- {
182
- $AADServicePrincipal = Get-MgServicePrincipal - Filter " AppID eq '$ ( $appInstance.AppId ) '" `
180
+ $AADServicePrincipal = [Array ](Get-MgServicePrincipal - Filter " DisplayName eq '$ ( $AppId -replace " '" , " ''" ) '" `
183
181
- Property $Script :PropertiesToExport `
184
- - Expand ' AppRoleAssignedTo'
182
+ - Expand ' AppRoleAssignedTo' )
183
+ if ($null -ne $AADServicePrincipal -and $AADServicePrincipal.Count -gt 1 )
184
+ {
185
+ Throw " Multiple Service Principal with the DisplayName $ ( $AppId ) exist in the tenant."
185
186
}
186
187
}
187
188
else
@@ -341,12 +342,36 @@ function Get-TargetResource
341
342
$appIdToExport = $AADServicePrincipal.AppId
342
343
}
343
344
345
+ $tagsValue = @ ()
346
+ if ($null -ne $AADServicePrincipal.Tags )
347
+ {
348
+ $tagsValue = [Array ]($AADServicePrincipal.Tags )
349
+ }
350
+
351
+ $alternativeNamesValue = @ ()
352
+ if ($null -ne $AADServicePrincipal.AlternativeNames )
353
+ {
354
+ $alternativeNamesValue = [Array ]($AADServicePrincipal.AlternativeNames )
355
+ }
356
+
357
+ $replyUrlsValue = @ ()
358
+ if ($null -ne $AADServicePrincipal.ReplyURLs )
359
+ {
360
+ $replyUrlsValue = [Array ]($AADServicePrincipal.ReplyURLs )
361
+ }
362
+
363
+ $servicePrincipalNamesValue = @ ()
364
+ if ($null -ne $AADServicePrincipal.ServicePrincipalNames )
365
+ {
366
+ $servicePrincipalNamesValue = [Array ]($AADServicePrincipal.ServicePrincipalNames )
367
+ }
368
+
344
369
$result = @ {
345
370
AppId = $appIdToExport
346
371
AppRoleAssignedTo = $AppRoleAssignedToValues
347
372
ObjectID = $AADServicePrincipal.Id
348
373
DisplayName = $AADServicePrincipal.DisplayName
349
- AlternativeNames = $AADServicePrincipal .AlternativeNames
374
+ AlternativeNames = $alternativeNamesValue
350
375
AccountEnabled = [boolean ]$AADServicePrincipal.AccountEnabled
351
376
AppRoleAssignmentRequired = $AADServicePrincipal.AppRoleAssignmentRequired
352
377
CustomSecurityAttributes = $complexCustomSecurityAttributes
@@ -358,11 +383,11 @@ function Get-TargetResource
358
383
Owners = $ownersValues
359
384
PreferredSingleSignOnMode = $AADServicePrincipal.PreferredSingleSignOnMode
360
385
PublisherName = $AADServicePrincipal.PublisherName
361
- ReplyURLs = $AADServicePrincipal .ReplyURLs
386
+ ReplyURLs = $replyUrlsValue
362
387
SamlMetadataURL = $AADServicePrincipal.SamlMetadataURL
363
- ServicePrincipalNames = $AADServicePrincipal .ServicePrincipalNames
388
+ ServicePrincipalNames = $servicePrincipalNamesValue
364
389
ServicePrincipalType = $AADServicePrincipal.ServicePrincipalType
365
- Tags = $AADServicePrincipal .Tags
390
+ Tags = $tagsValue
366
391
KeyCredentials = $complexKeyCredentials
367
392
PasswordCredentials = $complexPasswordCredentials
368
393
Ensure = ' Present'
0 commit comments