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

Add-MtTestResultDetail not adding details to custom tests #528

Open
ntatschner opened this issue Nov 8, 2024 · 1 comment
Open

Add-MtTestResultDetail not adding details to custom tests #528

ntatschner opened this issue Nov 8, 2024 · 1 comment

Comments

@ntatschner
Copy link

Hey all,

I'm trying to use Add-MtTestResultDetail to add details from a custom test, but unfortunately it's not working as documented.

I have 3 files in the "custom" folder, all with the same name, a .ps1, .Tests.ps1 and a .md

The test runs as expected and produces the overall status of the test.
I based the logic of the test on your existing tests and used the same logic to add the test details.

These are the files:
.ps1

function Find-RSYUsersMissingManagers {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'Exists is not a plurality')]
    [CmdletBinding()]
    [OutputType([bool])]

    # Retrieve all users from Microsoft Graph
    $users = Get-MgUser -All

    # Initialize an array to track users without a manager
    $usersWithoutManager = @()

    $result = $true

    # Loop through each user and ensure they have a manager assigned
    foreach ($user in $users) {
        # Fetch the manager for the current user
        $manager = Get-MgUserManager -UserId $user.Id -ErrorAction SilentlyContinue

        if ([string]::IsNullOrEmpty($manager)) {
            $result = $false
            $usersWithoutManager += [PSCustomObject]@{
                DisplayName       = $user.DisplayName
                UserPrincipalName = $user.UserPrincipalName
            }
        }
    }

    if ($result -eq $false) {
        $TestResults = "There were no users with out Managers assigned. Well Done! :raised_hands:"
    }
    else {
        $TestResults += "Could find managers on:`n`n"
        foreach ($u in $usersWithoutManager) {
            $TestResults += "- User: $($u.DisplayName) | UPN $($u.UserPrincipalName). :cry:`n"
        }
        Add-MtTestResultDetail -TestName "Manager Attribute: All users should have a manager attribute set" -Result $TestResults
    }
    return $result
}

.Tests.ps1

BeforeAll {
    . $PSScriptRoot/Find-RSYUsersMissingManagers.ps1
}
Describe "Rothesay" -Tag "Entra", "CustomTests", "AttributeTest" {
    It "Manager Attribute: All users should have a manager attribute set" {
        $result = Find-RSYUsersMissingManagers
        $result | Should -Be $true -Because "All users should have an assigned Manager"
    }
}

.md

### This test checks if there are any users without a manager assigned. 
##### Custom Rothesay Test
---

<!--- Results --->

%TestResult%

Any help would be appreciated and thank you for creating an amazing utility.

@ntatschner
Copy link
Author

Hey Maester community,

Has anyone else had this issue with custom tests? Anyone been able to add details to custom tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant