diff --git a/tests/Maester/Entra/Test-EntraRecommendations.Tests.ps1 b/tests/Maester/Entra/Test-EntraRecommendations.Tests.ps1 index 3d93bd1c..6e61c3a6 100644 --- a/tests/Maester/Entra/Test-EntraRecommendations.Tests.ps1 +++ b/tests/Maester/Entra/Test-EntraRecommendations.Tests.ps1 @@ -1,16 +1,21 @@ BeforeDiscovery { - $EntraRecommendations = Invoke-MtGraphRequest -DisableCache -ApiVersion beta -RelativeUri 'directory/recommendations?$expand=impactedResources' -OutputType Hashtable - Write-Verbose "Found $($EntraRecommendations.Count) Entra recommendations" + try { + $EntraRecommendations = Invoke-MtGraphRequest -DisableCache -ApiVersion beta -RelativeUri 'directory/recommendations?$expand=impactedResources' -OutputType Hashtable + Write-Verbose "Found $($EntraRecommendations.Count) Entra recommendations" + } catch { + Write-Verbose "Authentication needed. Please call Connect-MgGraph." + } } Describe "Entra Recommendations" -Tag "Maester", "Entra", "Security", "All", "Recommendation" -ForEach $EntraRecommendations { It "MT.1024: Entra Recommendation - . See https://maester.dev/docs/tests/MT.1024" -Tag "MT.1024", $recommendationType { - $EntraIDPlan = Get-MtLicenseInformation -Product "EntraID" + $EntraPremiumRecommendations = @( "insiderRiskPolicy", "userRiskPolicy", "signinRiskPolicy" ) + $EntraIDPlan = Get-MtLicenseInformation -Product "EntraID" if ( $EntraIDPlan -ne "P2" ) { $EntraPremiumRecommendations | ForEach-Object { if ( $id -match "$($_)$" ) { @@ -19,6 +24,12 @@ Describe "Entra Recommendations" -Tag "Maester", "Entra", "Security", "All", "Re } } } + + if ( $status -match "dismissed" ) { + Add-MtTestResultDetail -SkippedBecause Custom -SkippedCustomReason "Status:Dismissed for '$($id)'" + return $null + } + #region Add detailed test description $ActionSteps = $actionSteps | Sort-Object -Property 'stepNumber' | ForEach-Object { $_.text + "[$($_.actionUrl.displayName)]($($_.actionUrl.url))." @@ -36,7 +47,7 @@ Describe "Entra Recommendations" -Tag "Maester", "Entra", "Security", "All", "Re $impactedResourcesList += "| $($resourceResult) | [$($resource.displayName)]($($resource.portalUrl)) | $($resource.addedDateTime) | `n" } } - $ResultMarkdown = $insights + $impactedResourcesList + "`n`n#### Remediation actions:`n`n" + $ActionSteps + "`n`n ExcludeTag: $($recommendationType)" + $ResultMarkdown = $insights + $impactedResourcesList + "`n`n#### Remediation actions:`n`n" + $ActionSteps Add-MtTestResultDetail -Description $benefits -Result $ResultMarkdown #endregion # Actual test