@@ -26,6 +26,9 @@ $clientSecret = $actionContext.Configuration.clientSecret
2626# Define correlation property of groups - This has to be unique
2727$correlationProperty = " externalId"
2828
29+ # Check if correlationproperty exists
30+ $groupsCreated = New-Object System.Collections.Generic.List[System.Object ]
31+
2932# region functions
3033function Resolve-ZenyaErrorMessage {
3134 [CmdletBinding ()]
@@ -223,10 +226,12 @@ try {
223226 Write-Verbose " Querying group that matches filter [$ ( $filter ) ]"
224227
225228 $group = $null
226- $group = $groupsGrouped [" $ ( $correlationValue ) " ]
229+ if ($groupsGrouped -ne $null ){
230+ $group = $groupsGrouped [" $ ( $correlationValue ) " ]
231+ }
227232
228233 # If resource does not exist
229- if ($null -eq $group ) {
234+ if ($null -eq $group -and -not ( $groupsCreated .Contains ( $correlationValue )) ) {
230235 <# Resource creation preview uses a timeout of 30 seconds
231236 while actual run has timeout of 10 minutes #>
232237 # Example: Department (department differs from other objects as the property for the name is "DisplayName", not "Name")
@@ -251,6 +256,8 @@ try {
251256
252257 $createdGroup = Invoke-RestMethod @splatWebRequest - Verbose:$false
253258
259+ $groupsCreated.Add ($correlationValue )
260+
254261 $outputContext.AuditLogs.Add ([PSCustomObject ]@ {
255262 # Action = "" # Optional
256263 Message = " Created group [$ ( $correlationValue ) ] for resource [$ ( $resource | ConvertTo-Json ) ]"
0 commit comments