
Once a business turns on Microsoft 365 Copilot, the interesting question changes. It stops being “which AI tools are on our machines?” and becomes “what are people actually asking?” The prompts are where the real risk and the real value both sit. Someone pastes a client list into a chat. Someone else asks for a summary of a board pack. Without a way to look, you are guessing. ai-prompt-report.ps1 is how I read those prompts from the Microsoft Graph, in a read-only report you can hand to a business owner.
This is the third piece in a set. The first, How to Find the AI Apps Hiding on Your Windows Devices with a Free PowerShell Script, looks at what is installed on endpoints. The second, Finding Shadow AI in the Cloud, looks at cloud apps seen by Defender for Cloud Apps discovery. This one looks inside Microsoft 365 Copilot itself. Everything below comes from the script (version 1.6.0) and its documentation page, which I re-read on 4 December 2026, plus Microsoft’s own API reference. My own suggestions are labelled, and none of them are tested.
Read this first: it shows what people typed
Most of my scripts report on settings and software. This one reports on people. By default it returns the verbatim text of each user’s prompt, with their name, the time and the app they were using. That is sensitive information, and the prompts can contain anything a person chose to type, including personal, client or commercial details.
So before you run it, here is how I would approach it. This is my opinion, not a statement from the documentation, and I am not giving legal advice:
- Decide why you are looking, and write it down. A defined purpose such as a security review, an incident or a policy check is very different from curiosity.
- Tell staff. Privacy and workplace monitoring rules differ by place and by state, so get proper advice and make sure your acceptable use policy says what is reviewed.
- Scope it. The script lets you pick the users (
-UserPrincipalName) and the dates (-Days, or-StartDateand-EndDate). Use the smallest window and the fewest people that answer the question. - Protect the output. The HTML, JSON, CSV and text files all contain prompt text. Store them where only the people who need them can read them, and delete them when the review is done.
- Do not turn it into a leaderboard. Use it to find risky patterns and training gaps, not to judge individuals.
What it does
The documentation explains that the Activity explorer in Microsoft Purview DSPM for AI shows Copilot prompts but has no public API, so a script cannot query or export from it. This script reads from the Microsoft Graph AI Interaction History export instead, which the documentation describes as the same prompt and response store those views are built on. The request is getAllEnterpriseInteractions under /v1.0/copilot/users/{id}/interactionHistory.
A normal run, as the documentation describes it:
- Works out how to authenticate and, if needed, finds an existing app and certificate (more on that below).
- Lists users who hold a Microsoft 365 Copilot licence. That is one directory call, not a Purview search.
- Pulls each user’s interactions, in parallel on PowerShell 7, with a server-side date filter, pages of 100, and retry handling when Graph returns HTTP 429.
- Writes an HTML dashboard, a JSON file, a prompts-only CSV and a prompts-only text file.
The documentation says a normal run takes seconds to a couple of minutes. Older versions waited for a Purview audit query that could run from 5 to 45 minutes. That search is now opt-in with -IncludePurviewAudit, and when you turn it on it runs in the background while the prompts download.
What you get back
- The verbatim user prompt, when it was created, the user (ID, UPN and display name where the lookup works) and the Copilot app or host, such as Teams, Word, Outlook or BizChat.
- The AI response text, but only when you add
-IncludeResponses. - With
-IncludePurviewAudit, extra compliance metadata from the Purview audit record: accessed SharePoint and OneDrive files, sensitivity labels, public web search use, jailbreak and cross-prompt injection (XPIA) flags and policy-block flags. It also covers activity from AI apps that do not write interaction history, including connected and third-party AI apps and Copilot Studio agents. Those rows are metadata only.
Purview audit records do not hold the verbatim prompt. When both sources are present, the script matches an audit record to an interaction-history prompt for the same user when the times are close, and labels each row PurviewAndInteractionHistory, InteractionHistoryOnly or PurviewAuditOnly.
Requirements
- PowerShell 7 or newer is recommended. Parallel download uses
ForEach-Object -Parallel. Windows PowerShell 5.1 is accepted and runs one user at a time, but the documentation says 5.1 has not been tested with version 1.6.0. - The Microsoft Graph authentication module.
Install-Module Microsoft.Graph.Authentication -Scope CurrentUser. - The Australia/Sydney time zone. The CSV and text export are written in Sydney time, and the script stops if neither time zone ID is present on the computer.
- A Copilot licence per user. Each user needs a Microsoft 365 Copilot licence that includes the Microsoft Copilot with Graph-grounded chat service plan. Microsoft’s API reference says the same. Users without it are skipped. Graph answers those calls with 403, 404 or 412, which is a licensing result and not a permissions fault.
- A supported cloud. Global and US Government (L4 and L5/DoD) are supported, and the China cloud operated by 21Vianet is not. The
-Environmentparameter takes Global, USGov or USGovDoD.
Permissions
The key point is that AiEnterpriseInteraction.Read.All is an application permission. Microsoft lists delegated access as not supported for this API. A normal interactive sign-in cannot read prompt text, so you need an app registration with a certificate or client secret.
| Permission | Type | When |
|---|---|---|
| AiEnterpriseInteraction.Read.All | Application only | Required for verbatim prompts and responses. |
| User.Read.All | Application | List users and resolve display names. Not needed if you pass -UserPrincipalName. |
| LicenseAssignment.Read.All | Application | Select Copilot-licensed users. If it is not offered, the script uses Organization.Read.All. |
| AuditLogsQuery.Read.All | Delegated or application | Only with -IncludePurviewAudit. |
| InformationProtectionPolicy.Read.All | Application | Optional. Resolves sensitivity label GUIDs when audit results are collected. |
Setting up the app, safely
This is the part where I would slow down. The report runs as the app, so whoever holds that app’s certificate can read every prompt it is allowed to see. The script gives you four routes, and I would try them in this order.
1. Let the script look for an app you already have
If you do not supply a certificate or secret, the script searches on its own, without asking first, when it cannot already read prompt text. The documentation says the search is read-only and never changes the tenant. It looks for certificates in your Windows certificate stores and the script folder (plus any folders you add with -CertificateSearchPath), reads the tenant’s app registrations, and checks which ones already hold the roles the report needs. It signs in read-only with Application.Read.All only if your current session cannot list apps.
# Run only the scan
.\ai-prompt-report.ps1 -DiscoverApp -CertificateSearchPath 'Default'
# Or just run the report and let it search
.\ai-prompt-report.ps1 -Days 7
It then reports one of four results:
| Result | Meaning | What happens |
|---|---|---|
| A | An app has every prompt role and a certificate you hold. | The least-privileged ready app that is not flagged high-privilege is used and the report continues. A high-privilege app is used only if you confirm (default No). |
| C | An app has every role but its certificate is not on this computer. | Listed first, with hints to import the PFX, pass -CertificatePath, or run -AddCertificateToApp. |
| B | No app is ready. An app is missing roles, or only admin consent is missing. | A ranked table and the fix, either the roles to add or the consent-only step. |
| D | Nothing usable. | Guidance for -CreateApp. |
I like that the ranking prefers apps that look read-only and ranks apps that already hold write or high-privilege roles last, with a flag. Adding a read permission to a privileged app widens what anyone with its certificate can do. A dedicated read-only app is usually the safer choice, which is also what the documentation says.
2. Fix an existing app
Two explicit, separate modes change the tenant. Both need -AppId, support -WhatIf, show the exact change, and need you to type YES. They are never started by discovery:
# Add the missing report roles and grant consent
.\ai-prompt-report.ps1 -GrantMissingPermissions -AppId '<application (client) id>' -TenantId 'contoso.onmicrosoft.com' -WhatIf
.\ai-prompt-report.ps1 -GrantMissingPermissions -AppId '<application (client) id>' -TenantId 'contoso.onmicrosoft.com'
# Add a new certificate to an app that has the roles but no local certificate
.\ai-prompt-report.ps1 -AddCertificateToApp -AppId '<application (client) id>' -TenantId 'contoso.onmicrosoft.com' -WhatIf
The documentation says the first only adds missing roles and removes nothing. The second appends a new self-signed certificate valid for two years and keeps the existing keys. Admin rights are needed. Global Administrator, or Privileged Role Administrator with Application Administrator, covers the first. Wait 1 to 5 minutes after any change before you run the report.
3. Create a new read-only app with the script
# Preview, with no sign-in and no changes
.\ai-prompt-report.ps1 -CreateApp -WhatIf
# A real run
.\ai-prompt-report.ps1 -CreateApp -AppName 'Contoso-AIPromptReport'
This creates or reuses an Entra app and service principal, a self-signed certificate, uploads the public key and grants admin consent for the application permissions. You type YES before it creates anything. The default app name is CIAOPS-AIPromptReport-ReadOnly. One caution the documentation is clear about: this path has not been run against a live tenant. Only -WhatIf has been exercised. Review the preview and try it in a tenant where you can delete the app if you need to.
4. Do it by hand in the Entra admin center
Register an app for this directory only, upload a certificate (a client secret also works, but a certificate is preferable), add the three Microsoft Graph application permissions above, and grant admin consent. The documentation notes that adding a delegated permission does not make prompt export work.
Whichever route you use, keep the secret material out of the command line. The script reads the PFX password and any client secret from environment variables you name, and it never accepts the password as a parameter.
Running it
Download the script, check it, and run it from its folder. This download snippet is my own suggestion, built from the repository path in the link above:
$dest = 'C:\Tools\AIPrompt'
New-Item -ItemType Directory -Path $dest -Force | Out-Null
Invoke-WebRequest 'https://raw.githubusercontent.com/directorcia/Office365/master/ai-prompt-report.ps1' -OutFile "$dest\ai-prompt-report.ps1"
Unblock-File "$dest\ai-prompt-report.ps1"
Install-Module Microsoft.Graph.Authentication -Scope CurrentUser
Then, with an app that already has the roles and a certificate in your store, the documented form is:
.\ai-prompt-report.ps1 -Days 7 -TenantId 'contoso.onmicrosoft.com' -ClientId '<application (client) id>' `
-CertificateThumbprint '<thumbprint>' -NoLaunch
With a certificate file, put the password in an environment variable instead of the command line:
$env:AIPROMPT_PFX_PASSWORD = Read-Host 'PFX password' -MaskInput
.\ai-prompt-report.ps1 -TenantId 'contoso.onmicrosoft.com' -ClientId '<application (client) id>' `
-CertificatePath '.\Contoso-AIPromptReport.pfx' -CertificatePasswordEnvironmentVariable AIPROMPT_PFX_PASSWORD
-MaskInput is PowerShell 7. On Windows PowerShell 5.1 the documentation suggests Read-Host -AsSecureString and assigning the text to the environment variable in your session. More examples from the documentation:
# An explicit window
.\ai-prompt-report.ps1 -StartDate '2026-11-01' -EndDate '2026-11-08' -TenantId 'contoso.onmicrosoft.com' `
-ClientId '<application (client) id>' -CertificateThumbprint '<thumbprint>' -NoLaunch
# Specific users, with the AI responses included
.\ai-prompt-report.ps1 -UserPrincipalName 'first.user@contoso.com' -Days 30 -IncludeResponses -NoLaunch -PassThru
# Add Purview audit metadata (files, labels, risk flags, non-Copilot AI apps)
.\ai-prompt-report.ps1 -Days 14 -IncludePurviewAudit -TenantId 'contoso.onmicrosoft.com' `
-ClientId '<application (client) id>' -CertificateThumbprint '<thumbprint>' -NoLaunch
# HTML and JSON only, no prompts CSV or text file
.\ai-prompt-report.ps1 -Days 7 -NoPromptExport -NoLaunch -TenantId 'contoso.onmicrosoft.com' `
-ClientId '<application (client) id>' -CertificateThumbprint '<thumbprint>'
# Capture a summary object
$result = .\ai-prompt-report.ps1 -Days 7 -PassThru -NoLaunch -TenantId 'contoso.onmicrosoft.com' `
-ClientId '<application (client) id>' -CertificateThumbprint '<thumbprint>'
$result.PromptsWithTextCount
The script does not quietly write a metadata-only report if it cannot read prompt text. It prints an ACTION NEEDED notice and asks Continue without prompt text? with a default of No. On a host that cannot sign in for the app search, it stops with exit code 1 and writes nothing, unless you pass -SkipInteractionHistory or -UseDeviceCode.
The parameters that matter most
| Parameter | Default | What it does |
|---|---|---|
| -Days | 7 | Lookback, 1 to 180 days. Ignored when both -StartDate and -EndDate are set. |
| -StartDate / -EndDate | None | Explicit window. Local or UTC, converted to UTC. The end must be later than the start. |
| -UserPrincipalName | None | Limit to these users and skip directory enumeration. |
| -IncludeResponses | Off | Keep the AI response next to each prompt in the JSON and HTML. |
| -AllUsers | Off | Query every enabled member, not only Copilot-licensed users. Expect many licence 403s. |
| -IncludePurviewAudit | Off | Also run the Purview audit search for files, labels, risk flags and non-Copilot AI apps. |
| -TenantId / -ClientId | None | Tenant and app for a new app-only connection. |
| -CertificateThumbprint / -CertificatePath | None | Certificate from the store, or a .pfx or .cer file. |
| -CertificatePasswordEnvironmentVariable / -ClientSecretEnvironmentVariable | None | Names of the environment variables that hold the secret. |
| -Environment | Global | Global, USGov or USGovDoD. |
| -OutputDirectory | Script folder | Existing folder for the output files. It is not created for you. |
| -NoPromptExport | Off | Skip the prompts CSV and text file. HTML and JSON are still written. |
| -ThrottleLimit | 8 | Parallel Graph requests, 1 to 30. Ignored on Windows PowerShell 5.1. |
| -MaxUsers | 500 | Cap when users come from the directory. Up to 10,000. |
| -NoLaunch / -PassThru | Off | Do not open the report, and return a summary object. |
| -WhatIf / -Confirm | Supported. -WhatIf previews the setup modes with no sign-in and no change. |
The full list, including the discovery and Purview timing parameters, is in the documentation.
What you get
Four files are written together, named with a local millisecond timestamp, for example ai-prompt-report-20261202-093915-872.html. Files are written under a temporary name and moved into place only when complete. A failed run removes anything it published, and the script stops before calling Graph if a destination file already exists.
- HTML. One self-contained file with summary counts (interactions, verbatim prompts, active users, apps and hosts, labelled-resource accesses, web-grounded prompts and security or policy flags), per-user and per-app tables, and a prompt table with search and filters. You can export the visible rows to CSV or JSON, print to PDF and switch between light and dark mode. Prompt text is HTML-encoded.
- JSON. A
metadatablock (including how the app was chosen, whether prompt text was collected and any warnings), asummaryblock and one object per prompt. It is meant for downstream use in a SIEM, Power BI or your own scripts. - Prompts CSV. One row per user prompt, oldest first, with DateTime in Sydney time, UTC time, user, display name, app or host and the prompt. It is UTF-8 with BOM, correctly quoted for line breaks, and values that start with a formula character are prefixed with an apostrophe.
- Prompts text file. The same rows as readable blocks, easy to scan or paste.
The console never prints prompt text. It prints a summary: the users queried, how many had activity, the number of prompts with text, the number of AI apps or hosts, warnings and duration.
Reading the results
- Users with activity is not users licensed. The script counts users who had at least one interaction, not everyone it asked about.
- Zero prompts is not always a fault. It can mean the window was too short, nobody used Copilot, a retention policy deleted the interactions, you skipped interaction history, or you are looking for Copilot Studio agent transcripts, which this API does not return. The script suggests
-Days 30when a successful query returns nothing. - Know your two kinds of 403. A 403 with a licence or mailbox message just means that user is skipped and listed in a warning. A 401, or a 403 that is not about licensing, is a permission problem, so the script stops and prints the notice.
- Check the source label. Rows labelled
PurviewAuditOnlyare metadata, with no prompt text. - Look for patterns, not people. The HTML filters for web-grounded prompts, labelled resources and jailbreak or XPIA flags are the quickest way to see where governance needs work.
Limits worth knowing
- No Copilot Studio agent conversations. Both the documentation and Microsoft’s API reference say this API does not return them. Use
-IncludePurviewAuditfor agent metadata, but the prompt text for those turns is not in the audit record. - Retention. You can ask for 1 to 180 days, but you only get what the service still holds. A Purview retention policy for Copilot experiences can delete prompts before the window ends, and Microsoft notes the set of interactions returned depends on licensing and on which AI experiences write to the service. See Learn about retention for Copilot and AI apps.
- Throttling. The documentation says Microsoft allows 30 requests per second per app per tenant. The script defaults to 8 parallel requests and recommends 8 to 12. If runs are slow, lower the number rather than raising it.
- Directory cap. Directory-discovered runs query at most 500 users unless you raise
-MaxUsers. - Test status. This is the most important caveat in the documentation. The automatic discovery logic was tested against a simulated Graph with Pester, not a live tenant. Discovery outcomes A and B were run read-only against two live tenants on version 1.4.0. Outcomes C and D, the ranking,
-GrantMissingPermissions,-AddCertificateToAppand automatic app selection have not been run against a live tenant, and-CreateApphas only had-WhatIfrun. Version 1.6.0 has also not been tested on Windows PowerShell 5.1. Pilot it in a tenant you can afford to clean up.
Running it regularly (my suggestions, untested)
The documentation does not describe a scheduled deployment. What it does show is that app-only certificate sign-in works with -NoLaunch and that a host that cannot prompt will stop instead of hanging. Everything in this list is my own idea and I have not tried it:
- Use a dedicated read-only app with a certificate and run the script as a scheduled task or from your RMM, with
-NoLaunch -PassThru, a short-Dayswindow and an-OutputDirectorythat already exists and is locked down. - Think hard about the cadence. A monthly review with a stated purpose is easier to defend than a continuous feed of what staff type.
- If you only want counts and flags, keep in mind that
-NoPromptExportonly skips the CSV and text files. The JSON and HTML still carry the prompt text, so they need the same protection. - Set a retention rule for the output folder so old reports are deleted on a schedule.
- Compare the summary numbers over time, such as prompts with text, risk-flagged interactions and web-grounded prompts, and use the movement to decide where to train people.
Where it fits
I would use the three reports together. The endpoint inventory shows what is installed. The cloud discovery report shows which AI services the network is talking to. The prompt report shows what people are doing inside Copilot, which is the one place where the business has already paid for the AI. It also feeds an honest conversation about adoption: which teams use it well, which have not started, and where sensitive material is being handed to it. For compliance, Microsoft documents what Copilot activity is audited on its audit page for Copilot, which is the same family of records the optional Purview step reads.
The takeaway
Visibility into prompts is powerful, and that is exactly why I would handle it carefully. Start with a clear purpose, a small scope and a dedicated read-only app. Try it first in a tenant you can clean up, because parts of the setup have not been proven live. Then use the reports to improve policy and training, not to watch people.
Sources (checked 4 December 2026)
- ai-prompt-report.ps1 on GitHub (version 1.6.0, parameters and release notes)
- AI Prompt Report documentation (docs/ai-prompt-report.md)
- aiInteractionHistory: getAllEnterpriseInteractions (Microsoft Learn)
- Learn about retention for Copilot and AI apps (Microsoft Learn) and Audit logs for Copilot and AI applications (Microsoft Learn)
- How to Find the AI Apps Hiding on Your Windows Devices with a Free PowerShell Script and Finding Shadow AI in the Cloud (CIAOPS)