functions/general/Test-TmfTenant.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function Test-TmfTenant
{
    <#
        .SYNOPSIS
            Tests activated configurations against the connected Tenant.
        
        .DESCRIPTION
            This command tests the desired configuration against the Tenant you are connected to.
            You can connect to a Tenant using Connect-MgGraph.

        .PARAMETER Exclude
            Exclude resources from testing.
            For example: -Exclude groups, users
    #>

    [CmdletBinding()]
    Param (
        [string[]] $Exclude
    )
    
    begin
    {
        Test-GraphConnection -Cmdlet $PSCmdlet
        $tenant = Get-MgOrganization -Property displayName, Id
    }
    process
    {
        Write-PSFMessage -Level Host -FunctionName "Test-TmfTenant" -String "TMF.TenantInformation" -StringValues $tenant.displayName, $tenant.Id        
        foreach ($resourceType in ($script:supportedResources.GetEnumerator() | Where-Object {$_.Value.testFunction -and $_.Name -notin $Exclude} | Sort-Object {$_.Value.weight})) {
            if ($script:desiredConfiguration[$resourceType.Name]) {
                Write-PSFMessage -Level Host -FunctionName "Test-TmfTenant" -String "TMF.StartingTestForResource" -StringValues $resourceType.Name
                & $resourceType.Value["testFunction"] -Cmdlet $PSCmdlet | Beautify-TmfTestResult
            }            
        }
    }
    end
    {
    
    }
}