Set up Maester in BitBucket
This guide will walk you through setting up Maester in BitBucket and automate the running of tests using BitBucket Pipelines.
Set up your Maester tests repository in BitBucket
Section titled “Set up your Maester tests repository in BitBucket”Pre-requisites
Section titled “Pre-requisites”- If you are new to BitBucket, create an account at BitBucket.com for organizations
- If you use BitBucket.com, you can run your CI/CD pipelines workflows on BitBucket-hosted runners.
Create a blank new project to always use the latest available public Maester Tests
Section titled “Create a blank new project to always use the latest available public Maester Tests”- On the top bar, at the top, select ‘Create ’ and select ‘Repository’ from the dropdown.

-
Create a New Repository Create a repository
- Project: Choose an existing project or create a new one.
- Repository name: Give your repository a descriptive name (e.g., maester-tests).
- Select the checkbox Access Level: Private Repository

-
Once the repository is created, navigate to the Repository settings —> Settings in left navigation bar. From Settings toggle Enable Pipelines.

-
Click on the Configure bitbucket-pipelines.yml. and Click on the Starter Pipeline to create a pipeline. This will add the
bitbuckets-pipelines.ymlfile for Bitbucket CI/CD Pipeline. We need to edit the initial code for running public Maester tests.

There are many ways to authenticate with Microsoft Entra. We currently have tested client secrets, but there are probably more options available.
- Client secret uses a secret to authenticate with Microsoft Entra protected resources.
Create an Entra Application
Section titled “Create an Entra Application”- Open Entra admin center > Identity > Applications > App registrations
- Tip: enappreg.cmd.ms is a shortcut to the App registrations page.
- Select New registration
- Enter a name for the application (e.g.
Maester DevOps Account) - Select Register
Grant permissions to Microsoft Graph
Section titled “Grant permissions to Microsoft Graph”- Open the application you created in the previous step
- Select API permissions > Add a permission
- Select Microsoft Graph > Application permissions
- Search for each of the permissions and check the box next to each permission:
- AuditLog.Read.All
- DeviceManagementConfiguration.Read.All
- DeviceManagementManagedDevices.Read.All
- DeviceManagementRBAC.Read.All
- DeviceManagementServiceConfig.Read.All
- Directory.Read.All
- DirectoryRecommendations.Read.All
- EntitlementManagement.Read.All
- IdentityRiskEvent.Read.All
- NetworkAccess.Read.All
- OnPremDirectorySynchronization.Read.All
- OrgSettings-AppsAndServices.Read.All
- OrgSettings-Forms.Read.All
- Policy.Read.All
- Policy.Read.ConditionalAccess
- Reports.Read.All
- ReportSettings.Read.All
- RoleEligibilitySchedule.Read.Directory
- RoleManagement.Read.All
- RoleManagementAlert.Read.Directory
- SecurityIdentitiesSensors.Read.All
- SecurityIdentitiesHealth.Read.All
- SharePointTenantSettings.Read.All
- ThreatHunting.Read.All
- UserAuthenticationMethod.Read.All
To run preview Agent ID tests, also grant these application permissions:
- AgentIdentity.Read.All
- AgentIdentityBlueprint.Read.All
- AgentIdentityBlueprintPrincipal.Read.All
- Application.Read.All
- Optionally, search for each of the permissions if you want to allow privileged permissions:
- ReportSettings.ReadWrite.All
- Required to disable report obfuscation
- ReportSettings.ReadWrite.All
- Select Add permissions
- Select Grant admin consent for [your organization]
- Select Yes to confirm
(Optional) Grant permissions to Exchange Online
(Optional) Grant permissions to Exchange Online
Section titled “(Optional) Grant permissions to Exchange Online”The Exchange Online role-based access control (RBAC) implementation uses service-specific roles for applications. The configuration below establishes the authorization chain for the app registration you created in the previous steps.
The Exchange Online permissions are necessary to support tests that validate Exchange Online configurations, such as the CISA tests.
- Open the application you created in the previous step
- Select API permissions > Add a permission
- Select APIs that my organization uses > search for Office 365 Exchange Online > Application permissions
- Search for
Exchange.ManageAsApp - Select Add permissions
- Select Grant admin consent for [your organization]
- Select Yes to confirm
- Connect to the Exchange Online Management tools and use the following to set the appropriate permissions:
New-ServicePrincipal -AppId <Application ID> -ObjectId <Object ID> -DisplayName <Name>New-ManagementRoleAssignment -Role "View-Only Configuration" -App <DisplayName from previous command>(Optional) Grant permissions to Teams
(Optional) Grant permissions to Teams
Section titled “(Optional) Grant permissions to Teams”The Teams role-based access control (RBAC) implementation uses service-specific roles for applications. The configuration below establishes the authorization chain for the app registration you created in the previous steps.
The Teams permissions are necessary to support tests that validate Teams configurations.
- Open Roles and administrators
- Search and select Teams Reader
- Select Add assigment
- Select No member selected
- Search for the name of previously created application
- Select previously created application and select Select to confirm
- Select Next to confirm
- Ensure that Active and Permanently assigned are ticked
- Enter Justification
- Select Assign to confirm
(Optional) Grant permissions to Azure
(Optional) Grant permissions to Azure
Section titled “(Optional) Grant permissions to Azure”The Azure Role-Based Access Control (RBAC) implementation uses Uniform Resource Names (URNs) with a ”/” separator for hierarchical scoping. Some resources exist within the root (e.g., ”/”) scope, and Microsoft retains strict control over them by limiting supported interactions. As a Global Administrator, you can elevate access to become authorized for these limited interactions.
The Azure RBAC permissions are necessary to support tests that validate Azure configurations, such as the CISA tests.
The following PowerShell script will enable you, with a Global Administrator role assignment, to:
- Identify the Service Principal Object ID that will be authorized as a Reader (Enterprise app Object ID)
- Install the necessary Az module and prompt for connection
- Elevate your account access to the root scope
- Create a role assignment for Reader access over the Root Scope
- Create a role assignment for Reader access over the Entra ID (i.e., aadiam provider)
- Identify the role assignment authorizing your account access to the root scope
- Delete the root scope role assignment for your account
$servicePrincipal = "<Object ID of the Entra App>"$subscription = "<Subscription ID>"Install-Module Az.Accounts -ForceInstall-Module Az.Resources -ForceConnect-AzAccount#Elevate to root scope access$elevateAccess = Invoke-AzRestMethod -Path "/providers/Microsoft.Authorization/elevateAccess?api-version=2015-07-01" -Method POST
#Assign permissions to Enterprise AppNew-AzRoleAssignment -ObjectId $servicePrincipal -Scope "/" -RoleDefinitionName "Reader" -ObjectType "ServicePrincipal"New-AzRoleAssignment -ObjectId $servicePrincipal -Scope "/providers/Microsoft.aadiam" -RoleDefinitionName "Reader" -ObjectType "ServicePrincipal"
#Remove root scope access$assignment = Get-AzRoleAssignment -RoleDefinitionId 18d7d88d-d35e-4fb5-a5c3-7773c20a72d9|?{$_.Scope -eq "/" -and $_.SignInName -eq (Get-AzContext).Account.Id}$deleteAssignment = Invoke-AzRestMethod -Path "$($assignment.RoleAssignmentId)?api-version=2018-07-01" -Method DELETE(Optional) Grant permissions to SharePoint Online
(Optional) Grant permissions to SharePoint Online
Section titled “(Optional) Grant permissions to SharePoint Online”SharePoint Online tests require the PnP.PowerShell module and an Entra ID app registration configured for interactive login with SharePoint delegated permissions.
The SharePoint Online permissions are necessary to support tests that validate SharePoint Online configurations, such as the CISA SharePoint baseline controls.
Install PnP.PowerShell
Section titled “Install PnP.PowerShell”Install-Module PnP.PowerShell -Scope CurrentUserThe easiest way to create the required app registration is to follow the official PnP PowerShell guide:
Option A — Automatically create a new PnP app registration
Section titled “Option A — Automatically create a new PnP app registration”PnP provides a built-in cmdlet to create a dedicated app registration for interactive login. This is the quickest option and the one recommended in the PnP docs:
Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "Maester PnP" -Tenant [yourtenant].onmicrosoft.com -SharePointDelegatePermissions "AllSites.FullControl"This will:
- Create an Entra ID app registration with the required delegated permissions
- Configure
http://localhostas the redirect URI automatically - Prompt you to authenticate and provide consent
- Output the Client ID you will need for
Connect-Maester
If you prefer to start from the exact example in the PnP docs, run Register-PnPEntraIDAppForInteractiveLogin with their default parameters and add -SharePointDelegatePermissions "AllSites.FullControl" for Maester’s SharePoint tests.
Note: Maester’s SharePoint tests are read-only.
AllSites.FullControl(delegated) is sufficient.Important: After registering the app, open a new PowerShell session before running
Connect-Maester, as the registration process loads PnP assemblies that can conflict with Microsoft Graph.
Option B — Reuse the existing Maester app registration
Section titled “Option B — Reuse the existing Maester app registration”If you prefer not to create a separate app, you can update the Maester app registration you created earlier to also support PnP PowerShell interactive login.
1. Add the localhost redirect URI
- Open your Maester app registration in the Entra admin center
- Select Authentication > Add a platform > Mobile and desktop applications
- In the Custom redirect URIs field, enter
http://localhost(note:http, nothttps) - Select Configure
2. Add SharePoint delegated permissions
- Select API permissions > Add a permission
- Select SharePoint > Delegated permissions
- Search for and check
AllSites.FullControl - Select Add permissions
- Select Grant admin consent for [your organization] and confirm
3. Connect using the existing Client ID
You can retrieve the Client ID of your Maester app from Graph without looking it up manually. First connect to Graph, then query for the app by its display name:
# Connect to Graph firstConnect-Maester -Service Graph
# Retrieve the Client ID of the Maester app registration$clientId = (Get-MgApplication -Filter "displayName eq 'Maester DevOps Account'").AppIdThen connect to SharePoint Online in a new session using the retrieved Client ID. The SharePoint admin URL is auto-discovered from your tenant — no need to specify it manually:
# Open a new PowerShell session, then:Connect-Maester -Service Graph,SharePointOnline -SharePointClientId $clientIdImportant: After registering the app, open a new PowerShell session before running
Connect-Maester, as PnP assemblies loaded during the session can conflict with Microsoft Graph.
Option C — App-only access (automation / non-interactive)
Section titled “Option C — App-only access (automation / non-interactive)”For unattended runs (CI pipelines, scheduled tasks) where interactive login is not possible, use application permissions with certificate-based authentication.
1. Add SharePoint application permission
- Open your app registration in the Entra admin center
- Select API permissions > Add a permission
- Select SharePoint > Application permissions
- Search for and check
Sites.FullControl.All - Select Add permissions
- Select Grant admin consent for [your organization] and confirm
2. Upload a certificate
- Select Certificates & secrets > Certificates > Upload certificate
- Upload the public key (
.cer) of your certificate
3. Connect using Connect-Maester
Pass the certificate thumbprint directly to Connect-Maester using -SharePointCertificateThumbprint. -TenantId is required for thumbprint-based auth:
$params = @{ Service = @('Graph', 'SharePointOnline') SharePointClientId = "<App Client ID>" SharePointCertificateThumbprint = "<Certificate Thumbprint>" TenantId = "<Tenant ID or domain>"}Connect-Maester @paramsThe certificate must be present in the current user’s Windows certificate store. The SharePoint admin URL is auto-discovered — supply -SharePointAdminUrl to override it if needed.
Use the Client ID from Option A or Option B when connecting:
Connect-Maester -Service Graph,SharePointOnline -SharePointClientId "<Client ID>"The SharePoint admin URL is auto-discovered from your tenant’s initial domain. If auto-discovery does not work (e.g. government or custom-domain tenants), supply it explicitly:
Connect-Maester -Service Graph,SharePointOnline -SharePointClientId "<Client ID>" -SharePointAdminUrl "https://contoso-admin.sharepoint.com"For device code flow (e.g. non-interactive sessions):
Connect-Maester -Service Graph,SharePointOnline -SharePointClientId "<Client ID>" -UseDeviceCode(Optional) Grant Dataverse permissions for Copilot Studio tests
(Optional) Grant Dataverse permissions for Copilot Studio
Section titled “(Optional) Grant Dataverse permissions for Copilot Studio”Dataverse access is required for the Copilot Studio security tests (MT.1113–MT.1122) that evaluate Copilot Studio agent configurations.
Create an Application User in Power Platform
Section titled “Create an Application User in Power Platform”- Go to the Power Platform Admin Center → select your environment → Settings → Users + permissions → Application users
- Click New app user → Add an app → select the app registration created above
- Select the correct Business unit
- Assign a security role with read access:
- Basic User for simplicity, or
- A custom role (e.g.
Maester Security Reader) with Organization-level Read on: Agent (bot), Agent component (botcomponent), User (systemuser), and Connection Reference (connectionreference)
- Click Create
Configure Maester
Section titled “Configure Maester”Add the environment URL to maester-config.json:
{ "GlobalSettings": { "DataverseEnvironmentUrl": "https://org12345.crm.dynamics.com" }}Create a client secret
Section titled “Create a client secret”- Select Certificates & secrets > Client secrets > New client secret
- Enter a description for the secret (e.g.
Maester DevOps Secret) - Select Add
- Copy the value of the secret, we will use this value in the Azure Pipeline
Create Bitbucket repository variables
Section titled “Create Bitbucket repository variables”- Open your
maester-testsBitbucket repository and go to Repository settings. - Select Pipelines > Repository variables.
- Add the three secrets listed below. Make sure to check the checkbox (
[x]) for each variable.
- To look up these values you will need to use the Entra portal, open the application you created earlier and copy the following values from the Overview page:
- Visibility: Visible, Key: AZURE_TENANT_ID, Value: The Directory (tenant) ID of the Entra tenant
- Visibility: Visible, Key: AZURE_CLIENT_ID, Value: The Application (client) ID of the Entra application you created
- Visibility: Masked and hidden, Key: AZURE_CLIENT_SECRET, Value: The client secret you copied in the previous step
- Save each secret by selecting Add variable at the bottom.
Edit bitbucket-pipelines.yml file (using the pipeline editor or IDE)
Section titled “Edit bitbucket-pipelines.yml file (using the pipeline editor or IDE)”# Global optionsoptions: max-time: 120 # 2 hours max runtime for all pipelines
# Git clone behaviorclone: depth: 1 # Shallow clone for faster checkout
# Cache and service container definitionsdefinitions: caches: powershell: ~/.powershell
# Docker image options (global)image: mcr.microsoft.com/microsoftgraph/powershell:latest
# Pipeline configurationpipelines: custom: run-maester-tests: - stage: name: Maester Testing Stage # Step configuration steps: - step: name: Run Maester Tests size: 2x # Standard size caches: - powershell script: - mkdir test-results - mkdir public-tests - pwsh -c 'Write-host "Running in project $BITBUCKET_REPO_SLUG with results at $BITBUCKET_BUILD_NUMBER."' - | pwsh -Command ' # Connect to Microsoft Graph - Access environment variables correctly $clientSecret = ConvertTo-SecureString -AsPlainText "$env:AZURE_CLIENT_SECRET" -Force [pscredential] $clientSecretCredential = New-Object System.Management.Automation.PSCredential("$env:AZURE_CLIENT_ID", $clientSecret) Connect-MgGraph -TenantId "$env:AZURE_TENANT_ID" -ClientSecretCredential $clientSecretCredential -NoWelcome
# Install Maester Install-Module Maester -Force
# Latest public tests cd public-tests Install-MaesterTests cd ..
# Configure test results $PesterConfiguration = New-PesterConfiguration $PesterConfiguration.Output.Verbosity = "None" Write-Host "Pester verbosity level set to: $($PesterConfiguration.Output.Verbosity.Value)"
$MaesterParameters = @{ Path = "public-tests" PesterConfiguration = $PesterConfiguration OutputFolder = "test-results" OutputFolderFileName = "test-results" PassThru = $true NonInteractive = $true }
# Add DisableTelemetry parameter $MaesterParameters.Add("DisableTelemetry", $true) Write-Host "Pester telemetry set to: $($MaesterParameters.DisableTelemetry)"
# Run Maester tests $results = Invoke-Maester @MaesterParameters
# View summary report $results | Format-List Result, FailedCount, PassedCount, SkippedCount, TotalCount, TenantId, TenantName, CurrentVersion, LatestVersion
# Flag status to Bitbucket if ($results.Result -ne "Passed") { Write-Warning "Status = $($results.Result): see Maester Test Report for details." exit 1 } ' after-script: - pwsh -c 'Write-host "Report can be opened in artifacts - test-results/test-results.html."' artifacts: - test-results/**Manually running the Maester tests
Section titled “Manually running the Maester tests”To manually run the Maester tests workflow
- Open your
maester-testsBitBucket repository. - Select Piplines from the left pane
- Click Run pipeline on the top right pane.
- Select the branch you want to run the pipeline on (e.g., main) , select the Pipeline
custom:run-maester-testsand click Run.
- This will trigger the pipeline.

Viewing the test results
Section titled “Viewing the test results”- Open your maester-tests Bitbucket repository and go to Pipelines.
- Click on the latest pipeline run to inspect. Click on the Run Maester Tests step and select the artifacts tab on right.

- Click on the download icon to download the test results artifacts.

- Open the folder
test-resultsfrom the downloaded artifact to view the test results.
- Click on the
test-results.htmlpage to view the test result in your browser.

Schedule the Pipeline
Section titled “Schedule the Pipeline”- Go to the
Maester-Testsrepository in Bitbucket. - Click Pipelines then Schedules (at the top right), and then click New schedule.
- Choose the Branch (e.g. main) and Pipeline
custom:run-maester-tests: - Select how often you would like the pipeline to run (e.g. weekly).
FAQ / Troubleshooting
Section titled “FAQ / Troubleshooting”- Ensure you are monitoring your BitBucket Runner cost.