Skip to content

How do I collect from Microsoft 365?

The Nanitor Collector evaluates your Microsoft 365 tenant against the CIS Microsoft 365 Foundations benchmark. It reads your tenant's configuration through the Microsoft Graph API using an app registration you create in Microsoft Entra ID. Access is read-only — Nanitor never changes anything in your tenant.

Set up before August 2025, or since April 2026?

  • Before Nanitor v6.4.0 (August 2025): your collector is probably missing the Microsoft Graph PowerShell module and some newer permissions. See Remediation for existing customers.
  • Between April and September 2026: an earlier version of this article left out SecurityEvents.Read.All. Without it no Microsoft 365 results are collected at all. Check that it is granted (Step 3).

Prerequisites

  • A Windows collector host. The Microsoft Graph PowerShell cmdlets do not run on Linux. Microsoft 365 collection requires a Windows host.
  • Windows PowerShell 5.1 (built into Windows). The collector runs the checks with powershell.exe. PowerShell 7 may also be installed, but the Graph modules must be installed for Windows PowerShell — see Step 1.
  • Execution policy RemoteSigned or less restrictive, so the Graph modules can load. Check with Get-ExecutionPolicy -Scope LocalMachine; set if needed with Set-ExecutionPolicy RemoteSigned -Scope LocalMachine.
  • Outbound HTTPS from the collector host to login.microsoftonline.com and graph.microsoft.com.
  • An account with Global Administrator or Privileged Role Administrator in the tenant, to grant admin consent.

Step 1 — Install Required PowerShell Modules

Open Windows PowerShell (not PowerShell 7 / pwsh) as Administrator on the collector host and run:

Install-Module Microsoft.Graph -Scope AllUsers -Force -AllowClobber
Install-Module Microsoft.Graph.Beta -Scope AllUsers -Force -AllowClobber

Use Windows PowerShell, not PowerShell 7

The collector runs powershell.exe (Windows PowerShell 5.1). Modules installed from PowerShell 7 (pwsh) go to C:\Program Files\PowerShell\Modules, which Windows PowerShell does not load. If you install from PowerShell 7, the collector will report Connect-MgGraph is not recognized even though the module appears installed. -Scope AllUsers makes the module available to the collector's service account.

Why both modules?

Several Microsoft 365 Foundations benchmark controls query /beta/ Graph endpoints. Both Microsoft.Graph and Microsoft.Graph.Beta are required. Using -Scope AllUsers ensures the modules are available to the Nanitor collector service account.

Large download (~400 MB)

The Microsoft.Graph and Microsoft.Graph.Beta modules together download approximately 400 MB of packages. On slow or restricted connections the installation can appear to stall — do not cancel it. Allow up to 10–15 minutes on a slow link.

Offline or restricted environments

If the collector host has no direct internet access, stage the modules on a connected machine first:

Save-Module Microsoft.Graph -Path C:\ModuleCache -Force
Save-Module Microsoft.Graph.Beta -Path C:\ModuleCache -Force
Copy the contents of C:\ModuleCache to C:\Program Files\WindowsPowerShell\Modules on the collector host (a path Windows PowerShell loads modules from), or install from the local path using -Repository.

Verify, in Windows PowerShell:

Get-Module Microsoft.Graph -ListAvailable
Get-Module Microsoft.Graph.Beta -ListAvailable
Get-Module Microsoft.Graph.Authentication -ListAvailable

All three should return version information. If any returns nothing, the installation did not succeed for Windows PowerShell.


Step 2 — Register an application in Microsoft Entra ID

  1. Sign in to the Microsoft Entra admin center as a Global Administrator or Application Administrator.
  2. Go to Identity → Applications → App registrations → New registration.
  3. Enter a name (for example Nanitor Collector).
  4. Under Supported account types, select Accounts in this organizational directory only (Single tenant).
  5. Leave Redirect URI blank. Click Register.
  6. On the Overview page, note the Application (client) ID and Directory (tenant) ID.

Step 3 — Grant API permissions

In the app registration go to API permissions → Add a permission → Microsoft Graph → Application permissions (not Delegated) and add every permission below. Then click Grant admin consent for [your organization] and confirm every row shows a green check under Status.

Permission What it is used for
SecurityEvents.Read.All Microsoft Secure Score. Required — read at the start of every collection. If it is missing, no Microsoft 365 results are collected at all.
Policy.Read.All Authorization policy (user consent, guest access, guest invitations, tenant creation) and the admin consent workflow
Domain.Read.All Password expiration policy
RoleManagement.Read.Directory Global administrator count and privileged role members
User.Read.All Whether privileged accounts are cloud-only
Group.Read.All Public groups and the dynamic guest-user group
GroupSettings.Read.All Custom banned password list
Application.Read.All Third-party storage services in Microsoft 365 on the web
OrgSettings-AppsAndServices.Read.All "User owned apps and services" (M365 admin center → Settings → Org settings)
OrgSettings-Forms.Read.All Internal phishing protection for Microsoft Forms
DeviceManagementConfiguration.Read.All Intune: devices without a compliance policy are marked not compliant (Intune-licensed tenants only — see note below)
Directory.Read.All Directory-wide reads
GroupMember.Read.All Group membership checks
Organization.Read.All Tenant organisation settings
AuditLog.Read.All Audit log configuration

All permissions are read-only. Permissions without admin consent cause the controls that need them to report Error.

Intune-licensed tenants only

DeviceManagementConfiguration.Read.All is only meaningful for tenants with an active Microsoft Intune licence (included in Microsoft 365 Business Premium, E3, and E5). On tenants without Intune, the deviceManagement/settings endpoint returns HTTP 403 regardless of permissions granted, and that control is reported as Error. The other controls are not affected.

If you want to use Nanitor's full Intune device sync and compliance visibility features, see the Microsoft Intune integration guide.

OrgSettings permissions may not appear in search

OrgSettings-AppsAndServices.Read.All and OrgSettings-Forms.Read.All are relatively new Microsoft Graph scopes covering the M365 admin centre "Org settings" surface. Search for OrgSettings directly under Microsoft Graph → Application permissions. If they are not found there, check Office 365 Management APIs. Add them as Application permissions and grant admin consent.


Step 4 — Create a client secret

  1. In the app registration, go to Certificates & secrets → Client secrets → New client secret.
  2. Enter a description and choose an expiry (maximum 24 months).
  3. Click Add and copy the Value immediately — it is shown only once.

Client secrets expire

When the secret expires, every collection fails with Authentication failed: status code 401. Set a reminder to rotate the secret before it expires, then update the credential in Nanitor.


Step 5 — Add the credential in Nanitor

In Nanitor, go to Organization Management → Collectors → Credentials and add a credential.

Select Azure as the Access method and fill in:

  • Client ID — the Application (client) ID from Step 2
  • Tenant ID — the Directory (tenant) ID from Step 2
  • Client Secret — the value copied in Step 4

Add Azure credentials


Step 6 — Start data collection

Go to the Asset tab and select Add asset.

Add an Azure Cloud environment

In the dialog:

  • Set Asset type to Cloud
  • Select your Collector
  • Give the environment an identifiable Name
  • Set Cloud type to Microsoft
  • Select the Credential created in Step 5
  • Set a Label to define priority (can be done later)

The collector authenticates and runs the first collection. Results appear within a few minutes and are refreshed once every 24 hours.

If no results appear, confirm the Microsoft 365 Foundations benchmark is enabled under Administration → Organization Management → Benchmarks.


Verification

  1. In Entra ID, open Enterprise applications → [your app] → Permissions and confirm every permission from Step 3 is listed as granted by an admin.
  2. On the collector host, in Windows PowerShell, confirm Get-Module Microsoft.Graph -ListAvailable returns a version.
  3. Trigger a manual check-in and read the collector log. A healthy run shows Started getting Cloud ScapInfo / Ended getting Cloud ScapInfo with no Error running: lines between them.
  4. Confirm benchmark results appear on the asset in Nanitor.

A successful check-in is not the same as a complete collection

The collector log ends with Asset … successfully checked in even when individual controls could not be read. Look for Error running: lines. Controls that could not be read are reported as Error and count against the benchmark score, so fix them rather than ignoring them.


Troubleshooting

Find the message from your collector log in the left column.

Collector log shows Cause Fix
Failed to retrieve Scap Info from device: … get graph API data failed for win365 scap: Authentication failed: status code 403 SecurityEvents.Read.All missing or not admin-consented. This is a permissions problem, not a wrong password — no results are collected until it is fixed Add SecurityEvents.Read.All and grant admin consent (Step 3)
Failed to retrieve Scap Info from device: … ending in Authentication failed: status code 400 or 401 Wrong tenant ID or client ID, or the client secret is wrong or expired Check the IDs; rotate the secret (Step 4)
Error running: … 403 Forbidden on beta/admin/appsAndServices/settings or beta/admin/forms/settings, with "code":"UnknownError","message":"" OrgSettings-AppsAndServices.Read.All / OrgSettings-Forms.Read.All missing — common on setups made from older versions of this article Add both permissions and grant admin consent (Step 3)
Error running: … with 403 Forbidden on Get-MgGroup, Get-MgDomain, or Get-MgPolicyAuthorizationPolicy Missing Group.Read.All, Domain.Read.All, or Policy.Read.All application permission Add the missing permission and grant admin consent (Step 3)
Error running: … with Insufficient privileges or Authorization_RequestDenied on any other Get-Mg… command The permission for that control is missing Find the control in the Step 3 table, add the permission and grant admin consent
/beta/ endpoint checks fail, /v1.0/ checks pass Most often the two OrgSettings permissions are missing (row above); otherwise Microsoft.Graph.Beta is not installed Check the OrgSettings permissions first, then install Microsoft.Graph.Beta -Scope AllUsers (Step 1)
All controls return empty results despite a successful check-in Permissions are Delegated type instead of Application, or admin consent was not granted Verify all permissions are Application type with admin consent granted (Step 3)
Error running: … on v1.0/deviceManagement/settings Tenant has no Intune, or DeviceManagementConfiguration.Read.All is missing Add the permission. If the tenant has no Intune, this control will stay in Error
CommandNotFoundException: The term 'Connect-MgGraph' is not recognized Microsoft.Graph module not installed for the service account, or installed from PowerShell 7 only Install from Windows PowerShell with -Scope AllUsers (Step 1)
Cmdlets not found on a Linux collector Microsoft 365 collection requires Windows Use a Windows collector
No benchmark results after setup The collector has not checked in yet, or the benchmark is not enabled Trigger a manual check-in; enable Microsoft 365 Foundations in Organization Management

Permission changes take effect on the next collection — the collector requests a new access token every time it runs. Allow a few minutes after granting consent for Microsoft to apply the change.


Remediation for existing customers

If you configured M365 collection before August 2025 (Nanitor v6.4.0), you are likely affected by missing PowerShell modules, insufficient permissions, or both.

Missing PowerShell modules

Symptom: Collector logs show CommandNotFoundException: The term 'Connect-MgGraph' is not recognized. A successful checkin confirmation alone does not mean Graph data was collected. Always verify that benchmark results appear in the Nanitor UI after setup.

Fix: On the collector host, in Windows PowerShell run as Administrator:

Install-Module Microsoft.Graph -Scope AllUsers -Force -AllowClobber
Install-Module Microsoft.Graph.Beta -Scope AllUsers -Force -AllowClobber
Restart the Nanitor Collector service and trigger a manual checkin.

Insufficient API permissions

Symptom: Modules are installed but benchmark controls return empty results, return 403 Forbidden errors, or consistently fail.

Fix: Setups made before August 2025 usually have only SecurityEvents.Read.All — keep it, it is still required. Compare the permissions on your existing app registration against the full list in Step 3. Two scopes commonly missing from older setups are OrgSettings-AppsAndServices.Read.All and OrgSettings-Forms.Read.All. Add any missing permissions and click Grant admin consent. You do not need to create a new app registration.