functions/roleManagement/Test-AzurePIMroleManagement.ps1

function Test-AzurePIMroleManagement
{
    [CmdletBinding()]
    Param (
        [switch]$DoNotShowNoActionRequired
    )
    
    begin
    {
        Test-AzureConnection -Cmdlet $PSCmdlet
        $tenant = Get-AzTenant -TenantId (Get-AzContext).Tenant.Id
        $roleManagementResources = @("roleAssignments", "roleDefinitions", "roleManagementPolicies")
    }
    process
    {
        Write-PSFMessage -Level Host -FunctionName "Test-AzurePIMroleManagement" -String "AzurePIM.TenantInformation" -StringValues $tenant.Name, $tenant.Id        
        foreach ($resourceType in ($script:supportedResources.GetEnumerator() | Where-Object {$_.Value.testFunction -and $_.Name -in $roleManagementResources} | Sort-Object {$_.Value.weight})) {
            if ($script:desiredConfiguration[$resourceType.Name]) {
                Write-PSFMessage -Level Host -FunctionName "Test-AzurePIMroleManagement" -String "AzurePIM.StartingTestForResource" -StringValues $resourceType.Name
                if ($DoNotShowNoActionRequired) {
                    & $resourceType.Value["testFunction"] -Cmdlet $PSCmdlet | Beautify-AzurePIMTestResult -DoNotShowNoActionRequired
                }
                else {
                    & $resourceType.Value["testFunction"] -Cmdlet $PSCmdlet | Beautify-AzurePIMTestResult
                }                
            }            
        }
    }
    end
    {
    
    }
}