Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

425 excluded scopes not working as expected #431

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Scripts/Helpers/Confirm-PolicyResourceExclusions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function Confirm-PolicyResourceExclusions {
param (
$TestId,
$ResourceId,
$ScopeTable,
$ScopeTable,
$IncludeResourceGroups,
$ExcludedScopes,
$ExcludedIds,
Expand All @@ -24,7 +24,7 @@ function Confirm-PolicyResourceExclusions {
}
if (!$ScopeTable.ContainsKey($scope)) {
$PolicyResourceTable.counters.unmanagedScopes += 1
return $false, $resourceIdParts
return $false, $resourceIdParts
}
$scopeEntry = $ScopeTable.$scope
$parentList = $scopeEntry.parentList
Expand All @@ -34,20 +34,29 @@ function Confirm-PolicyResourceExclusions {
if (!$IncludeResourceGroups -and $scopeType -eq "resourceGroups") {
Write-Verbose "Exclude(resourceGroup) $($ResourceId)"
$PolicyResourceTable.counters.excluded += 1
return $false, $resourceIdParts
return $false, $resourceIdParts
}
foreach ($testScope in $ExcludedScopes) {
if ($scope -eq $testScope -or $parentList.ContainsKey($testScope)) {
if ($scope -like $testScope -or $parentList.ContainsKey($testScope)) {
Write-Verbose "Exclude(scope,$testScope) $($ResourceId)"
$PolicyResourceTable.counters.excluded += 1
return $false, $resourceIdParts
return $false, $resourceIdParts
}
elseif ($testScope -contains "*") {
foreach ($parentScope in $parentList.Keys) {
if ($parentScope -like $testScope) {
Write-Verbose "Exclude(scope,$testScope) $($ResourceId)"
$PolicyResourceTable.counters.excluded += 1
return $false, $resourceIdParts
}
}
}
}
foreach ($testExcludedId in $ExcludedIds) {
if ($TestId -like $testExcludedId) {
Write-Verbose "Exclude(id,$testExcludedId) $($ResourceId)"
$PolicyResourceTable.counters.excluded += 1
return $false, $resourceIdParts
return $false, $resourceIdParts
}
}
return $true, $resourceIdParts
Expand Down