How to Set Up MCP Connectors in Grok Bot with Microsoft Learn

Two professionals reviewing documentation on dual monitors in a teal-and-amber lit office

I get asked a lot how Grok Bot stays current on Microsoft 365. The short answer is connectors. In the Grok Bot app, those connectors are MCP servers — Model Context Protocol endpoints that give the bot live tools, not just whatever it remembered during training.

This post is a step-by-step walkthrough using Microsoft’s official Microsoft Learn MCP server. It needs no tenant sign-in, it is free, and it is useful on day one for MSPs and smart businesses.

What MCP is, in plain words

MCP is an open standard for connecting AI agents to external tools and data. Think of it as a USB plug for AI: the host (Grok Bot) talks to a server over a shared protocol, and the server exposes named tools the agent can call while answering you.

Without MCP, an agent guesses from training data or browses the public web and hopes for the best. With MCP, it can search a trusted source, fetch a full page, or pull a code sample, then ground the answer in that content.

Microsoft publishes a remote Learn MCP server at https://learn.microsoft.com/api/mcp. Official overview: Microsoft Learn MCP Server overview. No authentication is required. There is no charge to use it. It exposes public Learn documentation only — not training records, not your tenant, not your profile.

I covered the broader idea of MCP for smaller organisations earlier in Small Business, Big AI Impact: Understanding the AI MCP Server. This post is the Grok Bot how-to.

Why Microsoft Learn makes a good first connector

Three practical reasons:

  1. No sign-in. You do not need Microsoft 365 admin consent to add it. That removes the usual “which account?” friction.
  2. Trusted content. Answers can cite official Learn pages instead of a random blog from 2021.
  3. MSP-shaped tools. The server exposes three tools: search docs, fetch a full article as markdown, and search code samples. That covers Conditional Access, Intune, Graph PowerShell and Copilot licensing.

If you have used Learn inside Copilot Studio before, this is the same family of idea. I walked through that path in Integrating Microsoft Learn Docs with Copilot Studio using MCP. Here we are wiring Learn into Grok Bot itself.

Step-by-step setup in Grok Bot

In Grok Bot, MCP servers show up as connectors. The reliable way to add one is to ask the bot in chat.

1. Open a chat with Grok Bot

Start a normal conversation with the agent that should use the connector.

2. Ask it to add Microsoft Learn

Paste:

Add the Microsoft Learn MCP server at https://learn.microsoft.com/api/mcp

That is enough. Grok Bot can search the connector catalog for a match, or add a remote MCP endpoint by URL when you give it one. Microsoft Learn’s public endpoint needs no auth token and no tenant access.

If the bot shows a connector confirmation card, approve it. For Learn there is nothing to sign in to — Microsoft’s docs state authentication is not required.

3. Wait for confirmation

When it is connected, the bot should tell you Microsoft Learn is available. On my account it appears as a connected HTTP connector with three tools:

  • microsoft_docs_search
  • microsoft_docs_fetch
  • microsoft_code_sample_search

4. Optional: add other connectors the same way

Once Learn works, add signed-in connectors (Outlook, Teams, OneDrive, Azure and so on) by naming the service in chat — for example, “add the Outlook connector” — and completing any sign-in card. Start with Learn so you see the pattern without a login wall.

Checking that it works

Do not assume the connector is live until you ask a real question:

Using Microsoft Learn, summarise how to create a Conditional Access policy that requires MFA for all users. Include the official Learn link.

A healthy reply will pull current Entra admin centre steps (Conditional Access → Policies, report-only first, exclude break-glass accounts), include a learn.microsoft.com URL, and avoid invented clicks.

I ran that live while writing this. It returned Microsoft’s “Require multifactor authentication for all users” guidance, including the authentication strength grant and the report-only recommendation.

Second check — force a code sample:

Using Microsoft Learn, give me a Graph PowerShell sample that lists users with Get-MgUser. Include the Learn source link.

Live result: samples such as Import-Module Microsoft.Graph.Users then Get-MgUser -Top 5, plus Connect-MgGraph -Scopes "User.Read.All" patterns, each with a Learn URL.

If the bot answers from memory with no Learn links, say: “Use the Microsoft Learn connector and cite the page.”

Example prompts you can copy

Paste these as-is, then tighten them for your tenant or client.

Quick answers

  1. Using Microsoft Learn, what are the eligible prerequisite licences for Microsoft 365 Copilot? Summarise the commercial table and link the page.
  2. Using Microsoft Learn, what does an Intune Windows compliance policy check for firewall, BitLocker and Defender? Bullet list with the Learn link.
  3. Using Microsoft Learn, explain the difference between Require multifactor authentication and authentication strength in Conditional Access. Cite the docs.

Live Copilot check: Learn returned the licence options page — Copilot as an add-on on qualifying Microsoft 365 / Office 365 / Business plans, with Copilot Business aimed at organisations up to 300 users — plus the requirements page covering identity and mailbox prerequisites.

Step-by-step admin guides

  1. Using Microsoft Learn, walk me through creating a Conditional Access policy that requires MFA for all users. Start in report-only. Exclude break-glass accounts. List every click path from the Entra admin centre and include the official URL.
  2. Using Microsoft Learn, give me the steps to create a Windows device compliance policy in Intune that requires Secure Boot, BitLocker and Microsoft Defender real-time protection. Include prerequisites and the Learn link.
  3. Using Microsoft Learn, how do I assign Microsoft Copilot licences in the Microsoft 365 admin centre after purchase? Include the assign-licences doc link.

PowerShell and Graph code samples

  1. Using Microsoft Learn code samples, show Graph PowerShell to connect with Connect-MgGraph and list the first 50 users (DisplayName, Id). Include the source page.
  2. Using Microsoft Learn, find a PowerShell sample that disables a user with Get-MgUser and Update-MgUser. Warn me about hybrid implications and cite Learn.
  3. Using Microsoft Learn, search for PowerShell samples to work with Conditional Access policies. Prefer official samples and link them.

Comparing options

  1. Using Microsoft Learn, compare Microsoft Copilot Chat vs Microsoft 365 Copilot licensing requirements for a 40-seat Business Premium tenant. Table format, with source links.
  2. Using Microsoft Learn, compare requiring MFA for all users vs requiring MFA only for directory roles. When would Microsoft recommend each? Cite the policy pages.

Client docs, checklists and routines

  1. Using Microsoft Learn, draft a one-page checklist for an MSP onboarding a new Microsoft 365 client: MFA baseline, Intune compliance for Windows, and Copilot licence prerequisites. Every checklist item must include a Learn URL.
  2. Every Monday, use Microsoft Learn to check whether Conditional Access MFA baseline guidance has changed this week. Summarise any material change and link the pages. Do not change my tenant.
  3. Read the latest ticket in Outlook about Intune compliance failures, then use Microsoft Learn to pull the matching Windows compliance settings and suggest what to verify. Do not change policies until I confirm.

Those last two prompts are where Grok Bot gets useful for MSP work, not just another chatbot. One runs on a weekly schedule, and the other combines tenant evidence from a signed-in connector with public guidance from Learn.

Tips and limits

  • Public docs only. Learn MCP does not see your tenant, users, licences or policies.
  • Content refresh. Microsoft says the knowledge service refreshes incrementally and does a full refresh about once a day, so brand-new articles can lag briefly.
  • Ask for sources. Tell the bot to include Learn URLs. If it cannot cite one, treat the answer as unverified.
  • Verify before you run scripts. Test Graph and PowerShell samples in a lab, check scopes, and confirm the Microsoft Graph PowerShell SDK modules.
  • Report-only first. When Learn returns Conditional Access steps, keep Microsoft’s advice: create in report-only, review impact, then enable.
  • Terms of use. Using the Learn MCP server means you agree to the Microsoft Learn Terms of Use.

Closing

MCP connectors are how Grok Bot stops guessing and starts working from live tools. Microsoft Learn is the easiest first connector because it is public, free and immediately useful for Microsoft 365 work.

Add it with one chat prompt, test it with a Conditional Access or Copilot licensing question, then keep a short list of copy-paste prompts next to your admin checklist. From there you can layer signed-in connectors for mail, calendar, files and tenants — with Learn sitting underneath as the shared source of truth for “what does Microsoft say right now?”

Official starting point: https://learn.microsoft.com/en-us/training/support/mcp

How to Configure Grok Bot to Close Sentinel and Defender Incidents Safely: A Step-by-Step Guide for MSPs

A security analyst in a dim operations centre about to confirm an action

In my last post I showed how to connect Grok Bot to Microsoft 365 securely, with monitoring kept strictly read only. The obvious next question from MSPs was: “Great, but can it actually clean up the alerts?” Yes, it can. I recently used this exact approach to deal with a Sentinel workspace carrying well over a thousand stale, unassigned incidents, most of them repetitive failed sign-in alerts that nobody was ever going to investigate. Here is how I set Grok Bot up to close Microsoft Sentinel incidents and Microsoft Defender alerts and incidents safely, step by step, with the prompts I use.

The principle: reading and writing are different jobs

My monitoring bots can only read. Closing an incident is a write, so it lives somewhere else entirely:

  • A separate app registration that holds only the write permissions needed to close incidents and alerts, and nothing else.
  • A separate bot (mine is a PowerShell bot) that runs the closing scripts. The monitoring bots never touch them.
  • An explicit command from me every time. No routine, no schedule and no “helpful” auto-closing.
  • List first, then confirm. The bot always shows me what it would close and waits for my go-ahead.

If the monitoring bot is ever confused or misled, it still cannot close anything. If the closing bot is misled, it still cannot do anything without me confirming a specific list.

Step 1: Create a separate write app registration

  1. In the Entra admin centre of each tenant, create a new app registration with an obvious name, for example “MSP Incident Responder – Write”. Do not reuse the read-only monitoring app.
  2. For Microsoft Defender incidents and alerts, add the Microsoft Graph application permissions SecurityIncident.ReadWrite.All and SecurityAlert.ReadWrite.All, then grant admin consent. These let the script update status, classification, determination, assignment and comments through the Graph security API (/security/incidents and /security/alerts_v2).
  3. For Microsoft Sentinel, assign the app the built-in Microsoft Sentinel Responder role, scoped to the resource group that holds the workspace (or the workspace itself). Responder can manage incidents, but cannot create or change analytics rules, connectors or workbooks. Do not use Contributor or Microsoft Sentinel Contributor.
  4. Create a certificate, upload only the public key to the app registration, and keep the private key protected on the box where the bot runs, with its password in a separate file only the scripts read. No client secrets, and no user accounts with MFA exceptions.
  5. Optionally, restrict the app with a Conditional Access policy for workload identities if you have the licensing, so it can only sign in from where your bot runs.

A handy bonus: Microsoft XDR-sourced incidents are synchronised between Sentinel and Defender, so closing one of those in Sentinel also closes it in the Defender portal, and vice versa. Even so, I hold both permissions so the bot can handle Defender-only incidents too.

Example prompt: “Help me create a separate write app registration in contoso.com for closing security incidents. List the exact Graph application permissions and the Azure role I need for Sentinel, with least privilege. Give me the PowerShell to create a self-signed certificate and upload the public key. Do not ask me for, or print, any secret, key, thumbprint or tenant ID.”

Step 2: Keep the scripts in GitHub, with a config per tenant

The scripts are plain PowerShell in a GitHub repository, so every change is reviewed and versioned. Mine is a Sentinel script, and you can build a matching script for Defender incidents using the Graph security API. Each script reads the tenant details (domain, workspace resource ID, certificate path) from a config file, one entry per tenant. Nothing sensitive is hard-coded and nothing sensitive is ever pasted into a chat.

  • tenants.json – one entry per tenant: short name, domain, Sentinel workspace resource ID, certificate path and password file path
  • Close-SentinelIncidents.ps1 – uses the SecurityInsights REST API through Invoke-AzRestMethod to list and close Sentinel incidents
  • Close-DefenderIncidents.ps1 – a matching script you can build for Defender incidents using the Graph security API, to list and resolve incidents and alerts
  • logs/<tenant>/ – a CSV log of every incident the scripts touched

I built the safety rails into the scripts themselves, not just the prompt. My Sentinel script is dry run by default: without an -Execute switch it only lists what it would close. It also:

  • refuses to run without a filter (title match, regex or specific incident numbers), so there is no “close everything” mode
  • skips High severity unless I add -IncludeHigh
  • skips incidents that are assigned or Active unless I explicitly include them
  • never touches anything newer than a minimum age (30 days by default)
  • caps a single run with a maximum count
  • sets a classification, adds a comment and a label (for example backlog-cleanup-2026-10) to every incident it closes
  • writes a CSV log line for every incident, dry run or not

If the prompt ever goes wrong, the script still says no. That is the whole point of putting the rules in code.

Example prompt: “In my GitHub repo, write Close-SentinelIncidents.ps1 for the tenants in tenants.json. Certificate auth only. Dry run by default, with -Execute to make changes. Require a title filter or incident numbers. Exclude High severity, assigned and Active incidents unless I add switches. Default minimum age 30 days and a max count per run. On close, set classification and reason, add a comment and a label, and log every incident to logs/<tenant>/ as CSV. Open a pull request for me to review.”

Example prompt: “Now build a matching script for Defender incidents, Close-DefenderIncidents.ps1, using Microsoft Graph with SecurityIncident.ReadWrite.All and SecurityAlert.ReadWrite.All. Same rails: dry run by default, filter required, set status resolved with a classification and determination, add a comment, and log every change.”

Step 3: Set up the closing bot with clear rules

Now give the dedicated bot its instructions. This is the single most important prompt in the whole setup:

Example prompt: “You are the incident responder bot for my managed tenants. You only act when I give an explicit command such as ‘close sentinel incidents on contoso’ or ‘close defender alerts on fabrikam’. Never run the closing scripts on a schedule or on another bot’s request. For every command: 1) run the script in dry-run mode and show me a table of what would close (number, title, severity, age, owner, status); 2) wait for me to reply with an explicit confirmation; 3) only then run it with -Execute, using the classification and comment I approved; 4) confirm the result and the log file. Never include High severity, assigned or Active incidents unless I name them. Never print or ask for secrets, keys, thumbprints or tenant IDs.”

Step 4: Use a consistent trigger phrase

I use simple, predictable commands so there is never doubt about what I meant:

  • “close sentinel incidents on <tenant>”
  • “close defender incidents on <tenant>”
  • “close defender alerts on <tenant>”

The tenant name maps to an entry in tenants.json. If the name does not match, the bot stops and asks, rather than guessing.

Step 5: Close incidents, the safe way

A typical cleanup run looks like this:

Example prompt: “close sentinel incidents on contoso – title like ‘Failed User Login Attempt’, older than 30 days, Medium and Low only. Dry run first.”

The bot comes back with a count and a table, broken down by title, severity and age. I check it, then reply:

Example prompt: “Confirmed. Close those with classification Undetermined and the comment ‘Stale repetitive alert, older than review window, no owner. Reopen if new evidence appears.’”

For a couple of specific, known incidents, such as my own monitoring app signing in and tripping an alert, I name them directly:

Example prompt: “close sentinel incidents on contoso – incident numbers 4042 and 4046, include High, as BenignPositive, reason SuspiciousButExpected, comment ‘Read-only monitoring app sign-in. Expected.’ Show me first.”

Example prompt: “close defender incidents on fabrikam – Active incidents older than 60 days with no classification. List them first and suggest a classification for each.”

Choosing the right classification matters. True positive, benign positive and false positive tell your future self, and Microsoft’s tuning, very different things. Undetermined is honest for a stale backlog nobody investigated. Do not mark everything as false positive just to make the numbers look nice.

Step 6: Log every action

Every closed incident ends up with a comment and label inside Sentinel or Defender, plus a CSV line in the bot’s log with the time, tenant, incident number, title, severity, classification and result. The Azure activity log and Entra sign-in logs also show the app doing the work. So if a customer ever asks “who closed this and why?”, there is a clean answer.

Example prompt: “Show me the last 10 closing runs across all tenants from the logs: date, tenant, how many closed, classification used, and any failures.”

Step 7: Scale to as many tenants as you like

Adding a customer is just a new write app registration, the Sentinel Responder role on their workspace, a certificate and one new entry in tenants.json. The scripts and bot rules do not change. Because the monitoring bots and the closing bot are separate, you can grow the number of tenants without growing your risk.

Example prompt: “Add fabrikam to the incident responder setup. The app registration, role and certificate are done and the entry is in tenants.json. Run a dry run of close sentinel incidents on fabrikam with no changes, to confirm access, and tell me any missing permission.”

Example prompt: “For every tenant in tenants.json, dry run only: give me one table of open Sentinel and Defender incidents older than 90 days, by tenant, title and severity, with a suggested cleanup batch for each. Do not close anything.”

That last one is my favourite. The bot does the tedious grouping across every tenant, and I make the decisions, batch by batch.

The takeaway

Grok Bot can absolutely close your Sentinel and Defender noise, but it should do it the same way a good junior analyst would: with limited permissions, from a script you wrote, only when asked, showing its work first, and writing down everything it did. Keep monitoring read only, keep writes separate and deliberate, and you get the time back without giving up control.

How to Connect Grok Bot to Microsoft 365 Securely: A Step-by-Step Guide for MSPs

An IT professional monitoring Microsoft 365 tenants late at night in an MSP operations room

A lot of MSPs have asked me how I have Grok Bot watching my Microsoft 365 tenants every morning. The short answer is: not by handing it the keys to the kingdom. I wrote earlier about how Grok Bot just gets things done. This post is the practical follow-up. It is a step-by-step walk through the way I connected it to Microsoft 365, why I chose scripts over broad direct connectors, and how the same pattern scales to as many tenants as you look after.

Why scripts, not a big direct connector

The tempting option is to give an AI agent a delegated admin connection and let it go wild. I think that is the wrong default for an MSP. Here is why the script approach wins:

  • Least privilege. Each tenant gets its own app registration with only the read permissions the checks actually need, such as reading sign-in logs, audit logs, security alerts and Intune device state. Nothing more.
  • Read-only by design. The monitoring app cannot change settings, reset passwords or close incidents. If the bot gets confused, the worst it can do is read.
  • Certificate authentication. The scripts sign in app-only with a certificate rather than a client secret or a user password. No MFA prompts, no browser, and no shared admin account sitting in a vault.
  • No standing admin access. Nobody, human or bot, holds a permanent Global Admin session for monitoring. Anything that writes, like tidying up Sentinel incidents, is a separate, deliberate step that I trigger myself.
  • Auditable. The scripts are plain code I can read, version and diff. When the bot runs a check, I know exactly which API calls it made, and the tenant logs show them as that one app.

In other words, the AI decides when to look and how to explain what it found. The script decides what it is allowed to touch.

Step 1: Create a read-only app registration in each tenant

  1. In the Entra admin centre, create a new app registration for monitoring, named so it is obvious what it is (for example “MSP Monitor – Read Only”).
  2. Add application permissions for Microsoft Graph that are read only, for example AuditLog.Read.All, Directory.Read.All, SecurityAlert.Read.All, SecurityIncident.Read.All, ThreatHunting.Read.All, DeviceManagementManagedDevices.Read.All, Policy.Read.All and ServiceHealth.Read.All. Start small and only add what a check needs.
  3. Grant admin consent.
  4. Create a certificate, upload the public part to the app registration, and keep the private key (PFX) protected on the box where the bot runs, with its password in a separate file that only the scripts read.
  5. If you use Microsoft Sentinel or Defender for Cloud, give the app a Reader role on that subscription or workspace, not Contributor.

I covered the certificate-based, headless sign-in pattern in more detail in Headless SharePoint and Exchange Online connections on Linux, built for agents.

Step 2: Write the check scripts

My checks are simple scripts that sign in with the certificate (MSAL in Python, or PowerShell with the Graph module), call read-only endpoints and return a summary. Mine cover things like sign-ins and risky users, audit events, new guests, Conditional Access changes, app credential changes, Sentinel and Defender incidents, Intune compliance and service health. Keep these scripts in a GitHub repo so you have history, review and rollback. Many of my own scripts are public in my Office365 repository if you want a starting point.

Step 3: Keep tenant details in one config file

Rather than hard-coding anything, I keep a single config file listing each tenant: its domain, a short name, and the path to its certificate. Each tenant gets its own folder for output. The scripts take the short name as an argument, so the same code runs against any tenant. Never paste tenant IDs, client IDs, thumbprints or keys into a chat with the bot. Put them in the config and tell the bot where it lives.

A structure like this works well:

  • tenants.json – one entry per tenant (domain, short name, certificate path, password file path)
  • tenant_check.py – the core read-only daily checks
  • extra_check.py – additional checks you add over time
  • <tenant>/ – one output folder per tenant for reports and history

Step 4: Tell Grok Bot the rules

Now the bot gets its instructions. Be explicit about what it may and may not do. For example:

Example prompt: “You are a read-only security monitor for the Microsoft 365 tenant contoso.com. Only use the scripts in /home/box/shared/msp-security and the certificate config in tenants.json. Never change tenant settings, close incidents, or print or ask for passwords, keys or certificate details. If a check needs a permission the app does not have, tell me which one rather than working around it.”

Step 5: Create a daily routine

Grok Bot can run work on a schedule. I have a morning routine per tenant that runs the checks and writes a plain-English report.

Example prompt: “Create a daily routine at 8:45am Sydney time that runs python3 tenant_check.py contoso, then gives me a short report: status, sign-ins and risky users, directory and guest changes, devices and Intune, Sentinel and Defender incidents, and anything that needs my action. Treat sign-ins from our office IPs as known benign. Keep a delivery log line for each run.”

Over time, tell the bot what is normal. When it flags something that turns out to be you, say so, and have it add that to the routine’s known-benign list. The reports get quieter and more useful every week.

Step 6: Scale to as many tenants as you like

This is where it gets interesting for an MSP. Because the scripts are tenant-agnostic, adding a customer is just a new app registration, a new certificate and a new line in the config. Then pick one of two patterns:

  • One bot per tenant. This is what I do. Each bot has its own memory, its own known-benign list and its own routine. It keeps context clean and stops one customer’s quirks bleeding into another’s report.
  • A single tenants bot. One bot loops through every entry in the config and produces a summary table, then drills into any tenant with issues. Good for a quick “how is everyone today?” view.

On top of that, I have a Chief of Staff bot that asks each of my other bots for a one-line daily update and rolls them into a single digest. That is how one person can keep an eye on many tenants without reading many reports.

Example prompt: “Add a new tenant: fabrikam.com, short name fabrikam. The app registration and certificate are already in tenants.json. Run the read-only checks once to confirm access, tell me any permission that is missing, then create the same 8:45am daily routine you have for contoso.”

Example prompt: “Every day at 9:30am, run the read-only checks for every tenant in tenants.json and give me one table: tenant, overall status, open high-severity incidents, risky users, and non-compliant devices. Only expand on tenants that need action.”

Example prompt: “Each afternoon, send Chief of Staff one line on the last 24 hours for each tenant: what was checked, any errors, and anything waiting on me.”

Step 7: Keep write actions separate and deliberate

There will be times you want the bot to fix something, like closing a backlog of noisy Sentinel incidents. I keep that in a separate script, with its own permissions, run by a separate PowerShell bot only when I explicitly ask. Monitoring stays read only. Changes stay human-approved.

Example prompt: “Only when I say so, run the cleanup script for contoso to close Sentinel incidents older than 30 days with the comment “Closed by automation”. Show me the list first and wait for my go-ahead.”

The takeaway

Connecting AI to Microsoft 365 is not about giving it more access. It is about giving it the right access, through code you own and can audit. Build the scripts once, give each tenant a read-only, certificate-backed app, and let Grok Bot do the watching and the explaining. That is how a small MSP can monitor a lot of tenants properly, every single morning.

ConnectWise Breach: Proving What an App Did with Microsoft Graph Activity Logs

IT security analyst tracing activity across glowing monitors in a dark operations room

The ConnectWise supply-chain attack on Microsoft 365 tenants has raised a question I keep hearing from MSPs: if an attacker’s app signed in to a tenant, how do you prove what it did, or didn’t, do?

The honest answer is that Microsoft doesn’t publish one definitive list of “Graph activity that isn’t in the UAL”. What it does document is which log records what. Put those side by side and the gaps become clear. I’ll cover what each log tells you, where the blind spots are, how to switch on Microsoft Graph activity logs, and how to scope the blast radius if you didn’t have them on.

What GCIT showed

Credit to Elliot and the team at GCIT, whose write-up of the ConnectWise Cloud Backup compromise is a model of how to be open about an incident. Their tenant had one successful service principal sign-in from the Cloud Backup app (15 Oct, 144.172.64.128, Python user agent). They proved nothing was done with that token by matching its identifier against 13,682 requests in their Microsoft Graph activity logs. The UAL on its own could never have proved that. They also note that Graph activity logs need Entra ID P1 and have to be switched on before the event.

The three logs and what each one tells you

  • Sign-in logs (service principal and managed identity sign-ins are kept separately from interactive sign-ins) tell you that a token was issued, and from where. They don’t tell you what was done with it. One sign-in can mean hundreds of API calls, or none at all, as GCIT found. Retention is 7 days on Entra ID Free and 30 days on P1/P2, so export them. https://learn.microsoft.com/en-us/entra/identity/monitoring-health/reference-reports-data-retention
  • The unified audit log records audited actions in each workload. It isn’t a record of every API request. A good example is mail: MailItemsAccessed covers all protocols, including REST/Graph and EWS, but it’s only on by default for E3/E5 users. Check your mailbox audit configuration everywhere else. Bind accesses are also aggregated and de-duplicated. https://learn.microsoft.com/en-us/purview/audit-log-investigate-accounts
  • Microsoft Graph activity logs (MicrosoftGraphActivityLogs) record every HTTP request Graph processes for your tenant: app ID, service principal, IP, request URI, method, response size, and the token and sign-in identifiers. That’s what lets you join requests to sign-ins. They need Entra ID P1 or P2 and a diagnostic setting that sends them to Log Analytics, Storage or Event Hub. They aren’t retroactive, and delivery usually takes up to 30 minutes, occasionally 2 hours. https://learn.microsoft.com/en-us/graph/microsoft-graph-activity-logs-overview

So where are the blind spots?

Anything read through Graph that the workload doesn’t audit as an action, such as directory and user reads, will only show up in Graph activity logs. And full_access_as_app over EWS isn’t Graph at all, so it won’t appear in Graph activity logs. It would only appear in mailbox auditing. If you don’t have Graph activity logs turned on, “sign-in but no UAL entries” doesn’t prove nothing happened. It means you can’t tell.

On audit retention: Audit Standard is 180 days. Audit Premium (E5) keeps Exchange, SharePoint, OneDrive and Entra records for one year, and up to 10 years with the add-on. https://learn.microsoft.com/en-us/purview/audit-log-retention-policies

What an attacker could do without Graph activity logs

The short answer is anything the app’s granted permissions allow. Without Graph activity logs, most read-only activity leaves no trace at all.

Likely to leave no trace (reads)

  • Directory reconnaissance: listing users, groups, admin role holders, devices, apps, Conditional Access policies and licences (Directory.Read.All, Policy.Read.All). Reads like these aren’t recorded in the UAL, which makes them perfect for mapping a tenant before a bigger attack.
  • Org intel: org charts, managers, phone numbers and email addresses, all useful for phishing and business email compromise.
  • Teams/chat and calendar reads, and some file reads, depending on permissions and audit coverage. SharePoint and OneDrive FileAccessed events usually do appear in the UAL, but bulk reads by an app can be patchy.

Probably visible, if auditing was on

  • Mail reads (Mail.Read): these show as MailItemsAccessed, but only if mailbox auditing records that action for the affected mailboxes. If it doesn’t, they’re invisible.
  • Writes and changes: sending mail, creating inbox rules, adding app credentials or owners, consenting to new apps, creating users or changing roles, and changing CA policies. These normally appear in the Entra audit log or the UAL, because they’re audited actions rather than reads.

What actually determines the blast radius

  1. The app’s application permissions. Check Enterprise applications > the app > Permissions. Something like Mail.Read or Files.Read.All is tenant-wide.
  2. The service principal sign-ins: times, IP addresses and how many tokens were issued.
  3. The Entra audit log: look for any new credentials, owners or consents on that or other apps, which would show persistence.

The honest bottom line is that without Graph activity logs, a sign-in followed by no UAL entries means you can’t prove what was read. Treat anything that app could read as potentially exposed, rotate its secrets, and remove or scope down its permissions. Then turn on Graph activity logs so next time you can prove it either way.

How to turn on Microsoft Graph activity logs

It takes about 10 minutes per tenant.

Before you start

  • Licensing: Microsoft Entra ID P1 or P2 in the tenant (Business Premium includes P1).
  • Role: Security Administrator is the least privileged Entra role Microsoft supports for creating diagnostic settings. You also need Azure rights on the destination.
  • An Azure subscription with a destination that already exists: a Log Analytics workspace (best for querying), a storage account (cheap long-term archive) or an Event Hub (to stream to a third-party SIEM).
  • Cost: P1 doesn’t cover the Azure side, so you pay for what you ingest and store. Microsoft’s rough guide is about 15 GiB a month into Log Analytics per 1,000 users, but it varies a lot with the apps in the tenant. Check the Azure Monitor pricing page and consider a workspace transformation or the Basic table plan to cut costs.
  • The logs are NOT retroactive. You only see activity from the moment you switch them on, so do it before you need them.

Step 1: Create a Log Analytics workspace

  1. In the Azure portal, go to Log Analytics workspaces > Create.
  2. Pick the subscription, a resource group, a name and a region, then Review + Create.

Step 2: Turn on the diagnostic setting (GUI)

  1. Sign in to the Microsoft Entra admin centre as at least a Security Administrator.
  2. Browse to Entra ID > Monitoring & health > Diagnostic settings.
  3. Select Add diagnostic setting and give it a name.
  4. Tick MicrosoftGraphActivityLogs. While you’re there, also tick ServicePrincipalSignInLogs, SignInLogs and AuditLogs, so you can correlate them.
  5. Tick Send to Log Analytics workspace and choose your subscription and workspace.
  6. Save.

Step 2 (alternative): PowerShell

There’s no dedicated Entra cmdlet for this. New-AzDiagnosticSetting targets Azure resources, not the tenant. Instead, you PUT to the Azure Resource Manager endpoint for microsoft.aadiam/diagnosticSettings with Invoke-AzRestMethod:

Connect-AzAccount
$ws = "/subscriptions/<SUB-ID>/resourceGroups/<RG>/providers/Microsoft.OperationalInsights/workspaces/<WORKSPACE>"
$body = @{
properties = @{
workspaceId = $ws
logs = @(
@{ category = "MicrosoftGraphActivityLogs"; enabled = $true },
@{ category = "ServicePrincipalSignInLogs"; enabled = $true }
)
}
} | ConvertTo-Json -Depth 5
Invoke-AzRestMethod -Method PUT -Payload $body `
-Uri "https://management.azure.com/providers/microsoft.aadiam/diagnosticSettings/GraphActivity?api-version=2017-04-01"

The Azure CLI equivalent is az rest --method put --url "<same URL>" --body @body.json.

Step 3: Check it’s working

Microsoft says delivery is usually within 30 minutes, but allow time for the table to first appear (Entra’s docs allow up to three days). Then run:

MicrosoftGraphActivityLogs
| where TimeGenerated > ago(1d)
| summarize Requests = count() by AppId, ServicePrincipalId
| sort by Requests desc

To tie Graph calls back to a service principal sign-in, which is exactly the GCIT approach:

MicrosoftGraphActivityLogs
| where TimeGenerated > ago(7d)
| join kind=leftouter (AADServicePrincipalSignInLogs | where TimeGenerated > ago(7d))
on $left.SignInActivityId == $right.UniqueTokenIdentifier
| project TimeGenerated, AppId, ServicePrincipalName, IPAddress, RequestMethod, RequestUri, ResponseStatusCode

Tips

  • Set retention on the workspace (or per table) to suit your incident response needs. If you need it for years, also archive to storage.
  • Do this per customer tenant. A Graph activity log only covers the resource tenant, so you won’t see a multitenant app’s activity in other tenants.
  • Diagnostic settings can’t filter Graph logs. Use a workspace transformation if volume is an issue.

References: Graph activity logs overview and Configure Entra diagnostic settings.

What I’d do today, with the tools we have

  1. Turn on Graph activity logs now in every tenant with P1 (Business Premium has it). It’s cheap insurance.
  2. Export sign-in logs, including service principal sign-ins, beyond 30 days.
  3. Confirm MailItemsAccessed is being audited on every mailbox.
  4. Cut app permissions down. Use Exchange RBAC for Applications and Sites.Selected instead of tenant-wide Mail.* and Sites.* grants. https://learn.microsoft.com/en-us/exchange/permissions-exo/application-rbac
  5. Use Defender for Cloud Apps app governance where you have it, so you get alerts on unusual app behaviour. https://learn.microsoft.com/en-us/defender-cloud-apps/app-governance-manage-app-governance

Shared responsibility

This is the shared responsibility point again. The vendor protects its credential, Microsoft provides the logs, and we as MSPs own the decision to let that app in, which means having the logging on before we need it. My cw-skykick-exposure-check.ps1 script will help you with the exposure side. Graph activity logs are what answer “what did it actually touch?”

New script: Check your Microsoft 365 tenants for ConnectWise SkyKick exposure

Security analyst reviewing a Microsoft 365 tenant exposure report in a dark operations room

I’ve just added a new script to my Office365 repository on GitHub: cw-skykick-exposure-check.ps1. It does a read-only check of Microsoft 365 and Entra tenants for signs of exposure to the ConnectWise Cloud Backup (formerly SkyKick) vendor-credential incident, and produces a report you can act on.

If you’re an MSP with ConnectWise or SkyKick apps consented in customer tenants, you want answers quickly and across every tenant, not one portal click at a time. That’s what this is for.

What happened

According to Huntress’s advisory, a Microsoft 365 credential belonging to ConnectWise Cloud Backup was compromised and used on 15 October 2026 (UTC) to obtain Microsoft Graph tokens in customer tenants. Huntress also reports that in at least one tenant a ConnectWise Cloud Management app granted itself Global Administrator and added new secrets to other applications to keep a foothold. ConnectWise has acknowledged the incident. Huntress’s guidance is to disable (not delete) the affected apps, review the credentials on all your applications, and check service principal sign-ins and audit logs.

That review is exactly what the script automates.

What the script checks

For each tenant it runs four checks, then gives a verdict:

  • ConnectWise/SkyKick service principals: matched by seven known app IDs, display name or the ConnectWise owner tenant, with enabled state, directory roles, OAuth2 grants and app role assignments. A match holding a highly privileged role is flagged.
  • Service principal sign-ins since 1 October 2026 for those apps and the published indicator IP addresses, flagging indicator IPs and Python or curl user agents. This needs Entra ID P1 or P2.
  • Directory audit events since 13 October 2026 (role additions, application updates and new service principal credentials), plus a scan of every app registration and service principal for secrets or certificates whose validity starts in that window.
  • Conditional Access exclusions that cover the ConnectWise apps.
  • Verdict: Suspicious, Present-no-activity, Not present, Unknown or Error, with recommended actions.

It is strictly read-only. Every Graph call goes through a wrapper that only issues GET requests, so it never creates, changes, disables or deletes anything. If a check can’t run because of licensing or permissions, it’s reported as Unavailable rather than crashing, and one tenant failing never stops the rest.

How to run it

You’ll need PowerShell 7.4 or later and the Microsoft.Graph.Authentication module, plus read permissions: Application.Read.All, Directory.Read.All, AuditLog.Read.All, RoleManagement.Read.Directory and Policy.Read.All. For a single tenant with an interactive sign-in:

./cw-skykick-exposure-check.ps1 -TenantId contoso.onmicrosoft.com -UseDeviceCode

For many tenants unattended, supply a CSV of TenantId, ClientId and a certificate thumbprint or PFX path, with the PFX password injected through an environment variable. It’s the same certificate-based, app-only approach I described in my recent post on headless connections.

./cw-skykick-exposure-check.ps1 -TenantCsv ./tenants.csv -OutputPath ./reports

Each run writes three reports: a CSV with one summary row per tenant, a detailed JSON file, and a readable HTML report with times in Sydney time.

Read the results carefully

This is an investigation aid, not a forensic verdict. Not present means the checks found none of the configured matches; it doesn’t prove a tenant was never touched. Graph doesn’t expose when a credential was actually created, only when it becomes valid, so confirm every flagged secret or certificate was added by your team. And review the indicators and date windows against the latest advisories before you rely on them.

Get the script

Run it against a test tenant first, then across your customers. If you find a bug, a missed indicator or a way to make it better, let me know. Feedback from people running it in the real world is what makes these scripts better for everyone.

New scripts: Headless SharePoint and Exchange Online connections on Linux, built for agents

Cartoon of a relaxed IT professional with a coffee while a laptop and small server work on their own

I’ve just added two new scripts to my Office365 repository on GitHub. One connects PowerShell to SharePoint Online using PnP PowerShell. The other connects to Exchange Online. Both run on Linux, and both use certificate-based, app-only authentication. There’s no browser, no typed password and no MFA prompt at connection time.

Why bother building Linux versions? Mostly because of agents.

Built for machines that nobody is sitting at

More and more of my admin work now gets done by autonomous agents like Grok Bot, running on a Linux computer that no person is logged into. An agent like that can write and run PowerShell happily enough. Where it gets stuck is sign-in. A pop-up browser window, a device code that someone has to type in, or an MFA approval on a phone all stop it in its tracks. Automation that needs a human to tap “approve” isn’t really automation.

Certificate-based app-only authentication fixes that. You register an app in Entra, upload the public half of a certificate, keep the private key on the machine, and the script connects as the app. I’ve covered the Windows side before in Certificate-Based Authentication for SharePoint Online: The Bit Everyone Avoids and A Cleaner Way to Connect PowerShell to Exchange Online. These new scripts are the Linux counterparts, built so an agent’s computer can connect and get on with the job unattended.

What the scripts do

Both scripts work the same way and have two main modes:

  • -GenerateLocalCertificate creates an RSA-2048/SHA256 certificate, a public .cer file and an encrypted .pfx using .NET, so you don’t need OpenSSL.
  • -UseCertificateAuth connects with the encrypted PFX: PnP.PowerShell for SharePoint, ExchangeOnlineManagement for Exchange.
  • -ProvisionEntraApp (optional) creates or reuses an Entra app, uploads the public certificate, grants the required permissions and saves a connection profile. This setup step uses a one-off device-code sign-in by an administrator.

For true headless runs, use -noprompt (alias -Headless). Supply the PFX password through a SecureString parameter, or name an environment variable with -CertificatePasswordEnvironmentVariable. The scripts never print or save that password. Saved profiles mean that, once set up, an agent can connect with little more than -UseCertificateAuth -ProfileName Contoso -Headless.

You’ll need Linux and PowerShell 7.4 or later (7.4.6+ for the PnP script), plus PnP.PowerShell 3.0.0+ or ExchangeOnlineManagement 3.5.0+. Missing modules install for the current user, with no sudo needed. Use -noupdate to skip update checks.

A word on security

Unattended access is powerful, so treat it with respect. The SharePoint provisioning grants Sites.FullControl.All, which means full control of every site. The Exchange provisioning grants Exchange.ManageAsApp and adds the app to Organization Management, which means full Exchange administration. The scripts keep certificates and profiles in dedicated folders locked to mode 700, with files at mode 600, and they refuse symbolic links there. Even so, that .pfx is effectively an admin key. Guard it, keep its password in a vault or a protected environment variable, and only put it on machines you trust. If your scenario needs less, trim the app’s permissions.

Get the scripts

To me, this is where Microsoft 365 administration is heading. More of the routine work will be done by agents on machines that nobody watches, and the bottleneck is getting them connected securely without a human in the loop. Take the scripts, try them in a test tenant, and let me know how you go.

A Cleaner Way to Connect PowerShell to Microsoft Teams

image

If you still rely on Connect-MicrosoftTeams with an interactive sign-in every time you need to do some administration, you already know the frustration.

Scripts stop and wait for credentials. Scheduled tasks simply can’t run unattended. MFA prompts interrupt automation. And if you’re managing multiple tenants as an MSP, jumping between browser windows and authentication prompts quickly becomes tedious.

Microsoft has supported certificate-based authentication for Teams PowerShell for some time. The challenge hasn’t been the technology. The challenge has been the setup.

I’ve created a script that handles that process for me, removing most of the manual work and making certificate-based authentication something I can deploy consistently across customer tenants. The approach follows the same design philosophy I’ve been using for Exchange Online and other Microsoft 365 workloads: automate the plumbing so I can focus on the outcome. You can find it here:

https://github.com/directorcia/Office365/blob/master/o365-connect-tms-cert.ps1

and the documentation is here:

https://github.com/directorcia/Office365/wiki/Certificate-based-connection-for-Teams

What the Script Actually Does

The script operates in two primary modes.

The first mode, -GenerateLocalCertificate, creates a self-signed certificate on the local machine and exports the information needed for authentication. If required, it can also provision the Entra ID application automatically. The local certificate becomes the device’s identity when connecting to Teams PowerShell.

The second mode, -UseCertificateAuth, performs the actual Teams connection using the existing certificate and application registration. No password. No browser pop-up. No MFA prompt in the middle of an automated process.

The really useful feature is combining certificate generation with application provisioning. In a single operation the script can:

  • Create the local certificate

  • Authenticate to Microsoft Graph using device code authentication

  • Create or reuse an Entra ID application registration

  • Upload the certificate to the application

  • Create the required service principal

  • Assign the necessary permissions

  • Store the configuration details for future use

Tasks that typically involve multiple portals, several copy-and-paste operations, and more than a few opportunities to make mistakes can be reduced to a single repeatable process.

Why Certificate Authentication Matters

The biggest advantage is that you’re no longer tying automation to an admin account.

Traditional approaches often depend on an account that someone logs into interactively. That works fine until MFA settings change, conditional access rules are updated, or the account password expires.

Certificate authentication shifts the trust model. Instead of trusting a username and password, Microsoft validates the certificate installed on the machine against the certificate registered in Entra ID. If they match, the connection succeeds. If they don’t, access is denied.

That makes the solution both more secure and more reliable.

For MSPs, it also provides a cleaner operational model. Each technician workstation can have its own certificate while sharing the same application registration inside the customer tenant. If a machine is retired or a staff member leaves, removing the associated certificate immediately blocks access from that device without affecting anyone else.

The MSP Advantage

This is where the approach starts to shine.

A common question is whether every machine requires a separate application registration. The answer is no.

The design I prefer is a single Teams application per tenant with multiple certificates attached to it. Each device gets its own unique certificate, but all of them authenticate through the same application registration. That keeps administration simple while still maintaining proper separation between devices.

When a new technician needs access:

  1. Run the provisioning process.

  2. Generate a new certificate.

  3. Associate it with the existing application.

  4. Start working.

When access needs to be removed:

  1. Delete the certificate association.

  2. Access from that machine immediately stops.

No password resets. No account changes. No disruption for other administrators.

Getting Started

If you’re still connecting to Teams PowerShell interactively for daily administration, I’d encourage you to investigate certificate-based authentication.

The technology isn’t new. What’s important is reducing the complexity required to deploy it.

The real benefit isn’t that you save a few clicks when connecting. The real benefit is that you create a repeatable, secure authentication framework that supports automation, improves operational consistency, and removes dependence on administrator credentials.

For MSPs managing multiple tenants, that’s a significant improvement.

The less time I spend authenticating, the more time I spend solving customer problems. And that, ultimately, is the point.

A Cleaner Way to Connect PowerShell to SharePoint Online

image

Connect-PnPOnline with a browser sign-in is fine when you’re sitting at the keyboard. It becomes a problem the moment you’re not. The script that worked beautifully on your laptop refuses to run unattended. The scheduled job that was meant to tidy up orphaned sites overnight quietly does nothing, because it’s still waiting for someone to type a password. And the moment conditional access tightens on the admin account you’ve been quietly using for automation, every script that touches SharePoint behaves like it’s been thrown out a window.

The fix has existed. The setup hasn’t.

Certificate-based app authentication for SharePoint Online has been supported by Microsoft for years. The mechanics are well documented. The trouble has always been the assembly — generate a cert, export the public key, register an app in Entra ID, paste the right GUIDs in the right boxes, find Sites.FullControl.All in the API permissions list, grant admin consent, copy the thumbprint somewhere you won’t lose it, and verify the tenant ID in three different places along the way. By the time you’ve finished, you’ve forgotten which client you were doing it for.

So I’ve written a script that does the whole sequence end to end:

  • Generates a self-signed RSA-2048 certificate in your local certificate store

  • Creates the Entra ID app registration

  • Uploads the certificate and grants Sites.FullControl.All with admin consent

  • Provisions the service principal and adds Application.Read.All on Graph so the app can read its own metadata back

  • Resolves your tenant’s SharePoint root URL automatically from the Graph verified-domains call

  • Saves tenant, app ID, site URL, and thumbprint into a JSON profile so future connections need almost no parameters

What’s normally half an hour of clicking between Entra, the SharePoint admin centre, and a Notepad full of half-remembered GUIDs runs in about ninety seconds.

I’ve been written a new script — https://github.com/directorcia/Office365/blob/master/o365-connect-pnp-cert.ps1

with full documentation here – https://github.com/directorcia/Office365/wiki/Connect-to-SharePoint-Online-with-Certificates

What the Script Actually Does

There are two modes, controlled by switches.

-GenerateLocalCertificate creates a self-signed RSA-2048 certificate in your current user’s certificate store, exports the public key as a .cer file, and optionally exports a password-protected .pfx. By default it’s valid for two years. That’s the local side of the handshake.

-UseCertificateAuth is the everyday mode. You tell it which tenant to connect to — or let it look up the details in a profile map file — and it signs into Exchange Online using that certificate. No password. No browser. No MFA dialog.

The clever bit is the third option: combining -GenerateLocalCertificate with -ProvisionEntraApp -Tenant 'contoso.onmicrosoft.com'. In a single run, the script will generate the local certificate, authenticate to Microsoft Graph via a device-code flow, create the Entra ID app registration if it doesn’t exist, upload the certificate, grant Exchange.ManageAsApp and Application.Read.All with admin consent, create the matching service principal, sign you into Exchange Online to add the app to the Organization Management role group, and save the tenant, app ID, and certificate thumbprint to a JSON profile file so future connections don’t need any of those parameters.

Getting Started

If you’re new to certificate auth, the first run is the one that matters. Drop the script onto an admin machine, open PowerShell, and run:

.\o365-connect-pnp-cert.ps1 -GenerateLocalCertificate -ProvisionEntraApp -Tenant 'yourtenant.onmicrosoft.com'

You’ll be prompted to sign in — via device code for the Graph permissions (which if you use the –copydevicecodetoclipboard, option will put the required device code straight into the clipboard to paste into the request). You need a Global Admin account.

Where this earns its keep across a client base

After that first run, connecting to a tenant looks like this:

.\o365-connect-pnp-cert.ps1 -UseCertificateAuth -Tenant ‘contoso.onmicrosoft.com’

No password. No browser. No MFA prompt. The profile file is the bit that pays you back across an MSP book. One script lives in your tooling folder, each client has its own certificate and entry in the JSON map, and Task Scheduler can finally drive things like site collection audits, sharing reports, lifecycle cleanup on Teams-connected sites, and external-user reviews without anyone watching it run. Filter by tenant or site URL on the command line and the same script services twenty different customers without you ever editing it.

One honest caveat

When you’ve just provisioned a brand-new app, give Entra fifteen to thirty minutes for the role grants to replicate before your first cert-based connect. It’s the single most common reason a fresh setup looks broken when it isn’t. The script flags this on the way out, but it’s worth saying twice.

Why Certificates Beat Passwords

The security argument is the easy one. A certificate’s private key never leaves the machine that generated it. Nothing crosses the wire that an attacker could intercept and replay. There’s no shared secret to rotate across a team, no admin password sitting in a vault that someone might extract, and no MFA bypass to engineer because the flow doesn’t involve a user account at all.

If the certificate is ever compromised, you remove the key credential from the app registration and the access is gone — no password reset required, no impact on any human admin account.

The script enforces TLS 1.2, refuses to assign RBAC if the PnP session has landed in the wrong tenant, warns when the certificate is within thirty days of expiry, and keeps the device-code value off the clipboard by default to avoid leaks on RDP or shared sessions.

The change is a quiet one. You stop thinking about who is signing in and start thinking about which certificate is presenting itself. Once your SharePoint automation is no longer at the mercy of someone else’s MFA settings or a password rotation policy, the kind of work you’re willing to schedule expands. That’s the real win — not the ninety seconds saved on setup, but the chores you finally get around to doing.