From c06a237d8c392740beb673b9295afe7d6b39933c Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Sat, 14 Nov 2026 14:10:06 +0100 Subject: [PATCH 1/4] fix(entra): show the detected emergency access account when MT.1005 passes In auto-detection mode the pass branch only set the result, so the report showed the failure text with an empty type and an unreplaced %TestResult% placeholder. The detection now runs in both cases: a pass names the detected user or group, and the failure output is unchanged. When the display-name lookup throws, the result shows the object ID. --- .../Test-MtCaEmergencyAccessExists.Tests.ps1 | 54 +++++++++++++++++++ tests/maester/entra/Test.MT.1005.ps1 | 49 ++++++++++------- 2 files changed, 83 insertions(+), 20 deletions(-) diff --git a/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 b/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 index dbd4ccc6fb..8ac87fc6ea 100644 --- a/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 @@ -2,6 +2,8 @@ BeforeAll { Import-Module $PSScriptRoot/../../Maester.psd1 -Force Mock -ModuleName Maester Get-MtLicenseInformation { return "P1" } + # Keep the tests off Microsoft Graph; tests that need display names mock Invoke-MtGraphRequest again + Mock -ModuleName Maester Invoke-MtGraphRequest { return $null } # Test user and group IDs $script:emergencyUserId1 = "11111111-1111-1111-1111-111111111111" @@ -225,6 +227,58 @@ InModuleScope Maester -Parameters @{ C = $config } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue } + + It 'Should name the detected account, not the failure text, when it passes (auto-detected)' { + $policy = Get-PolicyWithUserExclusion -UserIds @($emergencyUserId1) + $script:capturedResult = $null + + Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } + Mock -ModuleName Maester Invoke-MtGraphRequest { return @{ id = $emergencyUserId1; displayName = 'Emergency User 1' } } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result) + $script:capturedResult = $Result + } + + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue + $script:capturedResult | Should -BeLike "*Automatically detected emergency access*Emergency User 1 ($emergencyUserId1)*" + $script:capturedResult | Should -BeLike '*All Conditional Access policies exclude this emergency access user.*' + $script:capturedResult | Should -Not -BeLike "*don't have the emergency access*" + $script:capturedResult | Should -Not -BeLike '*%TestResult%*' + } + + It 'Should still pass and show the ID when the display name cannot be read (auto-detected)' { + $policy = Get-PolicyWithUserExclusion -UserIds @($emergencyUserId1) + $script:capturedResult = $null + + Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } + Mock -ModuleName Maester Invoke-MtGraphRequest { throw 'Request_ResourceNotFound' } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result) + $script:capturedResult = $Result + } + + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue + $script:capturedResult | Should -BeLike "*user: $emergencyUserId1*" + } + + It 'Should list the policies that miss the detected account when it fails (auto-detected)' { + $policies = Get-MultiplePoliciesMixedExclusions -UserIds @($emergencyUserId1) -GroupIds @() + $script:capturedResult = $null + $script:capturedObjects = $null + + Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policies } + Mock -ModuleName Maester Invoke-MtGraphRequest { return @{ id = $emergencyUserId1; displayName = 'Emergency User 1' } } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result, $GraphObjects) + $script:capturedResult = $Result + $script:capturedObjects = $GraphObjects + } + + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse + $script:capturedResult | Should -BeLike "*Automatically detected emergency access*Emergency User 1 ($emergencyUserId1)*" + $script:capturedResult | Should -BeLike "*don't have the emergency access user excluded*" + @($script:capturedObjects).displayName | Should -Be 'Policy 2 - Missing Exclusions' + } } Context "Single user configured as emergency access" { diff --git a/tests/maester/entra/Test.MT.1005.ps1 b/tests/maester/entra/Test.MT.1005.ps1 index 74c34af210..05b8b7f980 100644 --- a/tests/maester/entra/Test.MT.1005.ps1 +++ b/tests/maester/entra/Test.MT.1005.ps1 @@ -59,34 +59,43 @@ $ExcludedGroupObjectGUID = $policies.conditions.users.excludeGroups | Group-Object -NoElement | Sort-Object -Property Count -Descending | Select-Object -First 1 -ExpandProperty Name $ExcludedGroups = $policies.conditions.users.excludeGroups | Group-Object -NoElement | Sort-Object -Property Count -Descending | Select-Object -First 1 | Select-Object -ExpandProperty Count - # If the number of enabled policies is not the same as the number of excluded users or groups, there is no emergency access - if ($PolicyCount -eq $ExcludedUsers -or $PolicyCount -eq $ExcludedGroups) { - $result = $true - } else { - # If the number of excluded users is higher than the number of excluded groups, check the user object GUID - $CheckId = $ExcludedGroupObjectGUID - $EmergencyAccessUUIDType = 'group' - if ($ExcludedUsers -gt $ExcludedGroups) { - $EmergencyAccessUUIDType = 'user' - $CheckId = $ExcludedUserObjectGUID - } + # If the number of excluded users is higher than the number of excluded groups, check the user object GUID + $CheckId = $ExcludedGroupObjectGUID + $EmergencyAccessUUIDType = 'group' + if ($ExcludedUsers -gt $ExcludedGroups) { + $EmergencyAccessUUIDType = 'user' + $CheckId = $ExcludedUserObjectGUID + } - # Get displayName of the emergency access account or group - if ($CheckId) { + # Get displayName of the emergency access account or group + if ($CheckId) { + try { if ($EmergencyAccessUUIDType -eq 'user') { $DisplayName = Invoke-MtGraphRequest -RelativeUri "users/$CheckId" -Select displayName | Select-Object -ExpandProperty displayName } else { $DisplayName = Invoke-MtGraphRequest -RelativeUri "groups/$CheckId" -Select displayName | Select-Object -ExpandProperty displayName } - - Write-Verbose "Emergency access account or group: $CheckId" - $testResult = "Automatically detected emergency access`n`n* $($EmergencyAccessUUIDType): $DisplayName ($CheckId)`n`n" + } catch { + Write-Verbose "Could not get the display name of emergency access $EmergencyAccessUUIDType $($CheckId): $_" + $DisplayName = $null } - $policiesWithoutEmergency = $policies | Where-Object { $CheckId -notin $_.conditions.users.excludeUsers -and $CheckId -notin $_.conditions.users.excludeGroups } - $policiesWithoutEmergency | Select-Object -ExpandProperty displayName | Sort-Object | ForEach-Object { - Write-Verbose "Conditional Access policy $_ does not exclude emergency access $EmergencyAccessUUIDType" - } + Write-Verbose "Emergency access account or group: $CheckId" + $detected = if ($DisplayName) { "$DisplayName ($CheckId)" } else { $CheckId } + $testResult = "Automatically detected emergency access`n`n* $($EmergencyAccessUUIDType): $detected`n`n" + } + + # If the number of enabled policies is not the same as the number of excluded users or groups, there is no emergency access + if ($PolicyCount -eq $ExcludedUsers -or $PolicyCount -eq $ExcludedGroups) { + $result = $true + $testResult += "All Conditional Access policies exclude this emergency access $EmergencyAccessUUIDType." + Add-MtTestResultDetail -Result $testResult + return $result + } + + $policiesWithoutEmergency = $policies | Where-Object { $CheckId -notin $_.conditions.users.excludeUsers -and $CheckId -notin $_.conditions.users.excludeGroups } + $policiesWithoutEmergency | Select-Object -ExpandProperty displayName | Sort-Object | ForEach-Object { + Write-Verbose "Conditional Access policy $_ does not exclude emergency access $EmergencyAccessUUIDType" } $testResult += "These Conditional Access policies don't have the emergency access $EmergencyAccessUUIDType excluded:`n`n%TestResult%" From 8ddb988d1e156559a614c426708d764d0e7a398e Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Sat, 14 Nov 2026 14:57:08 +0100 Subject: [PATCH 2/4] fix(entra): start the MT.1005 pass message with Well done The test guide in .github/skills/maester-test-expert/SKILL.md asks every pass message to start with Well done. The auto-detection pass message now starts with it, then names the detected account the way the configured-accounts message lists them. --- .../tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 | 3 +-- tests/maester/entra/Test.MT.1005.ps1 | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 b/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 index 8ac87fc6ea..ae638d912f 100644 --- a/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 @@ -240,8 +240,7 @@ } InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeTrue - $script:capturedResult | Should -BeLike "*Automatically detected emergency access*Emergency User 1 ($emergencyUserId1)*" - $script:capturedResult | Should -BeLike '*All Conditional Access policies exclude this emergency access user.*' + $script:capturedResult | Should -BeLike "Well done. All Conditional Access policies exclude the automatically detected emergency access user:*Emergency User 1 ($emergencyUserId1)*" $script:capturedResult | Should -Not -BeLike "*don't have the emergency access*" $script:capturedResult | Should -Not -BeLike '*%TestResult%*' } diff --git a/tests/maester/entra/Test.MT.1005.ps1 b/tests/maester/entra/Test.MT.1005.ps1 index 05b8b7f980..dc2750ca4b 100644 --- a/tests/maester/entra/Test.MT.1005.ps1 +++ b/tests/maester/entra/Test.MT.1005.ps1 @@ -88,7 +88,7 @@ # If the number of enabled policies is not the same as the number of excluded users or groups, there is no emergency access if ($PolicyCount -eq $ExcludedUsers -or $PolicyCount -eq $ExcludedGroups) { $result = $true - $testResult += "All Conditional Access policies exclude this emergency access $EmergencyAccessUUIDType." + $testResult = "Well done. All Conditional Access policies exclude the automatically detected emergency access $($EmergencyAccessUUIDType):`n`n* $($EmergencyAccessUUIDType): $detected`n" Add-MtTestResultDetail -Result $testResult return $result } From f0d1dce4a7df1e6b7924b80f9203daf5c4bc4546 Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Sat, 14 Nov 2026 15:12:25 +0100 Subject: [PATCH 3/4] fix(entra): leave GuestsOrExternalUsers out of MT.1005 auto-detection excludeUsers can hold the GuestsOrExternalUsers keyword, which names a category of users, not an account. Auto-detection counted it like an account: a tenant whose policies all exclude guests passed MT.1005 with no emergency access account, and the pass message named the keyword as the detected user. The keyword is now left out before counting, so such a tenant fails and the check looks at real accounts. --- .../Test-MtCaEmergencyAccessExists.Tests.ps1 | 35 +++++++++++++++++++ tests/maester/entra/Test.MT.1005.ps1 | 6 ++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 b/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 index ae638d912f..dd6c78215c 100644 --- a/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 @@ -278,6 +278,41 @@ $script:capturedResult | Should -BeLike "*don't have the emergency access user excluded*" @($script:capturedObjects).displayName | Should -Be 'Policy 2 - Missing Exclusions' } + + It 'Should not take GuestsOrExternalUsers for an emergency access account (auto-detected)' { + $policy = Get-PolicyWithUserExclusion -UserIds @('GuestsOrExternalUsers') + $script:capturedResult = $null + + Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result) + $script:capturedResult = $Result + } + + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse + $script:capturedResult | Should -Not -BeLike '*GuestsOrExternalUsers*' + } + + It 'Should check the excluded account, not GuestsOrExternalUsers, when policies exclude both (auto-detected)' { + $policies = @( + Get-PolicyWithUserAndGroupExclusion -UserIds @('GuestsOrExternalUsers', $emergencyUserId1) -GroupIds @() + Get-PolicyWithUserExclusion -UserIds @('GuestsOrExternalUsers') + ) + $script:capturedResult = $null + $script:capturedObjects = $null + + Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policies } + Mock -ModuleName Maester Invoke-MtGraphRequest { return @{ id = $emergencyUserId1; displayName = 'Emergency User 1' } } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result, $GraphObjects) + $script:capturedResult = $Result + $script:capturedObjects = $GraphObjects + } + + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse + $script:capturedResult | Should -BeLike "*Emergency User 1 ($emergencyUserId1)*" + @($script:capturedObjects).displayName | Should -Be 'Policy With User Exclusion' + } } Context "Single user configured as emergency access" { diff --git a/tests/maester/entra/Test.MT.1005.ps1 b/tests/maester/entra/Test.MT.1005.ps1 index dc2750ca4b..f208560e3b 100644 --- a/tests/maester/entra/Test.MT.1005.ps1 +++ b/tests/maester/entra/Test.MT.1005.ps1 @@ -54,8 +54,10 @@ $PolicyCount = $policies | Measure-Object | Select-Object -ExpandProperty Count if (-not $EmergencyAccessAccounts -or $EmergencyAccessAccounts.Count -eq 0) { Write-Verbose "No emergency access accounts or groups defined in the Maester config. Use the default logic to detect emergency access accounts or groups." - $ExcludedUserObjectGUID = $policies.conditions.users.excludeUsers | Group-Object -NoElement | Sort-Object -Property Count -Descending | Select-Object -First 1 -ExpandProperty Name - $ExcludedUsers = $policies.conditions.users.excludeUsers | Group-Object -NoElement | Sort-Object -Property Count -Descending | Select-Object -First 1 | Select-Object -ExpandProperty Count + # GuestsOrExternalUsers names a category of users, not an account, so it can't be the emergency access account + $ExcludedUserIds = @($policies.conditions.users.excludeUsers | Where-Object { $_ -ne 'GuestsOrExternalUsers' }) + $ExcludedUserObjectGUID = $ExcludedUserIds | Group-Object -NoElement | Sort-Object -Property Count -Descending | Select-Object -First 1 -ExpandProperty Name + $ExcludedUsers = $ExcludedUserIds | Group-Object -NoElement | Sort-Object -Property Count -Descending | Select-Object -First 1 | Select-Object -ExpandProperty Count $ExcludedGroupObjectGUID = $policies.conditions.users.excludeGroups | Group-Object -NoElement | Sort-Object -Property Count -Descending | Select-Object -First 1 -ExpandProperty Name $ExcludedGroups = $policies.conditions.users.excludeGroups | Group-Object -NoElement | Sort-Object -Property Count -Descending | Select-Object -First 1 | Select-Object -ExpandProperty Count From b9b05b93b888d056d94380a5d75eb44d3c13191c Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Tue, 17 Nov 2026 19:20:49 +0100 Subject: [PATCH 4/4] fix(entra): give MT.1005 a message of its own when auto-detection finds no candidate When no policy excluded a specific user or group, for example only GuestsOrExternalUsers, MT.1005 failed with a sentence about the emergency access group: group was the default type, not a detected one. With no user-targeted policy at all, the same sentence came with a raw %TestResult% placeholder (#2814). Both cases now fail with a sentence of their own, and the automatically detected line is built on the fail path, the only one that used it. The verdicts do not change. --- .../Test-MtCaEmergencyAccessExists.Tests.ps1 | 55 ++++++++++++++++++- tests/maester/entra/Test.MT.1005.ps1 | 17 +++++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 b/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 index dd6c78215c..f96d45ad9e 100644 --- a/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCaEmergencyAccessExists.Tests.ps1 @@ -282,15 +282,68 @@ It 'Should not take GuestsOrExternalUsers for an emergency access account (auto-detected)' { $policy = Get-PolicyWithUserExclusion -UserIds @('GuestsOrExternalUsers') $script:capturedResult = $null + $script:capturedObjects = $null Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } Mock -ModuleName Maester Add-MtTestResultDetail { - param($Result) + param($Result, $GraphObjects) $script:capturedResult = $Result + $script:capturedObjects = $GraphObjects } InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse $script:capturedResult | Should -Not -BeLike '*GuestsOrExternalUsers*' + # Nothing was detected, so the result must not name a type + $script:capturedResult | Should -BeLike 'No emergency access account or group could be detected:*' + $script:capturedResult | Should -Not -BeLike '*emergency access group*' + @($script:capturedObjects).displayName | Should -Be 'Policy With User Exclusion' + } + + It 'Should not name a type when no policy excludes a specific user or group (auto-detected)' { + $policy = Get-PolicyWithNoExclusions + $script:capturedResult = $null + $script:capturedObjects = $null + + Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result, $GraphObjects) + $script:capturedResult = $Result + $script:capturedObjects = $GraphObjects + } + + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse + $script:capturedResult | Should -BeExactly "No emergency access account or group could be detected: none of these Conditional Access policies excludes a specific user or group.`n`n%TestResult%" + @($script:capturedObjects).displayName | Should -Be 'Policy Without Exclusions' + } + + It 'Should say no user-targeted policy was found, with no placeholder, when there is no policy (auto-detected)' { + $script:capturedResult = $null + $script:capturedObjects = $null + + Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return @() } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result, $GraphObjects) + $script:capturedResult = $Result + $script:capturedObjects = $GraphObjects + } + + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse + $script:capturedResult | Should -BeExactly 'No user-targeted Conditional Access policy was found, so no emergency access account or group could be detected.' + $script:capturedObjects | Should -BeNullOrEmpty + } + + It 'Should say no user-targeted policy was found when only an Agent Identity policy exists (auto-detected)' { + $policy = Get-PolicyAgentIdentity + $script:capturedResult = $null + + Mock -ModuleName Maester Get-MtConditionalAccessPolicy { return $policy } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result) + $script:capturedResult = $Result + } + + InModuleScope Maester -Parameters @{ C = $null } { Test-MtCaEmergencyAccessExists -EmergencyAccessAccounts $C } | Should -BeFalse + $script:capturedResult | Should -BeExactly 'No user-targeted Conditional Access policy was found, so no emergency access account or group could be detected.' } It 'Should check the excluded account, not GuestsOrExternalUsers, when policies exclude both (auto-detected)' { diff --git a/tests/maester/entra/Test.MT.1005.ps1 b/tests/maester/entra/Test.MT.1005.ps1 index f208560e3b..11f8ca3396 100644 --- a/tests/maester/entra/Test.MT.1005.ps1 +++ b/tests/maester/entra/Test.MT.1005.ps1 @@ -54,6 +54,13 @@ $PolicyCount = $policies | Measure-Object | Select-Object -ExpandProperty Count if (-not $EmergencyAccessAccounts -or $EmergencyAccessAccounts.Count -eq 0) { Write-Verbose "No emergency access accounts or groups defined in the Maester config. Use the default logic to detect emergency access accounts or groups." + + # Detection reads the exclusions of user-targeted policies, so without one there is nothing to detect + if ($PolicyCount -eq 0) { + Add-MtTestResultDetail -Result 'No user-targeted Conditional Access policy was found, so no emergency access account or group could be detected.' + return $result + } + # GuestsOrExternalUsers names a category of users, not an account, so it can't be the emergency access account $ExcludedUserIds = @($policies.conditions.users.excludeUsers | Where-Object { $_ -ne 'GuestsOrExternalUsers' }) $ExcludedUserObjectGUID = $ExcludedUserIds | Group-Object -NoElement | Sort-Object -Property Count -Descending | Select-Object -First 1 -ExpandProperty Name @@ -84,7 +91,6 @@ Write-Verbose "Emergency access account or group: $CheckId" $detected = if ($DisplayName) { "$DisplayName ($CheckId)" } else { $CheckId } - $testResult = "Automatically detected emergency access`n`n* $($EmergencyAccessUUIDType): $detected`n`n" } # If the number of enabled policies is not the same as the number of excluded users or groups, there is no emergency access @@ -95,12 +101,19 @@ return $result } + # No policy excludes a specific user or group, so there is no candidate and no type to name + if (-not $CheckId) { + $testResult = "No emergency access account or group could be detected: none of these Conditional Access policies excludes a specific user or group.`n`n%TestResult%" + Add-MtTestResultDetail -GraphObjects $policies -GraphObjectType ConditionalAccess -Result $testResult + return $result + } + $policiesWithoutEmergency = $policies | Where-Object { $CheckId -notin $_.conditions.users.excludeUsers -and $CheckId -notin $_.conditions.users.excludeGroups } $policiesWithoutEmergency | Select-Object -ExpandProperty displayName | Sort-Object | ForEach-Object { Write-Verbose "Conditional Access policy $_ does not exclude emergency access $EmergencyAccessUUIDType" } - $testResult += "These Conditional Access policies don't have the emergency access $EmergencyAccessUUIDType excluded:`n`n%TestResult%" + $testResult = "Automatically detected emergency access`n`n* $($EmergencyAccessUUIDType): $detected`n`nThese Conditional Access policies don't have the emergency access $EmergencyAccessUUIDType excluded:`n`n%TestResult%" Add-MtTestResultDetail -GraphObjects $policiesWithoutEmergency -GraphObjectType ConditionalAccess -Result $testResult return $result