Finding Shadow AI in the Cloud: A Free PowerShell Report from Defender for Cloud Apps Discovery

Studio photograph of translucent glass spheres on a dark reflective surface, some with small amber glowing orbs inside

An inventory of what is installed on a laptop only tells you half the story. Plenty of AI tools never touch the disk. They live in a browser tab, and the only trace is the network traffic. If your clients already feed firewall or proxy logs, or Defender for Endpoint signals, into Microsoft Defender for Cloud Apps, then that traffic has already been catalogued as discovered cloud apps. The question is how to get it out in a form you can put in front of a business owner. That is what ai-shadow-report.ps1 does.

This post covers what the script reports, what it needs, how to run it, how to read the results and where I would be careful. It is the cloud-side companion to the endpoint script I covered in How to Find the AI Apps Hiding on Your Windows Devices with a Free PowerShell Script. Everything about the script comes from the code and the Shadow AI and Cloud Discovery Report documentation, both of which I re-read on 1 December 2026. My own suggestions are labelled as such.

Endpoint inventory versus cloud discovery

The two scripts answer different questions, and I would run both:

Endpoint script (ai-apps-report.ps1)Cloud discovery script (ai-shadow-report.ps1)
Where it looksThe Windows device itself: apps, processes, shortcuts, browser and editor extensionsCloud app discovery data in Microsoft Defender for Cloud Apps, read through Microsoft Graph
What it can seeWhat is installed or running locallyCloud apps your network or devices have talked to, including ones that only live in a browser
What it cannot seeWebsites visited with no local traceAnything that is not in your discovery streams
NeedsPowerShell on the device, no tenant accessA tenant with populated Cloud Discovery data, and Graph consent

One tells you what is on the machine. The other tells you what the machines and the network are reaching. Neither tells you what was typed into them.

What the script does

It is a read-only Microsoft Graph report. According to the script and the documentation, it:

  • loads the built-in AI detection rules, plus an optional catalog file;
  • signs in to Microsoft Graph with the single delegated scope CloudApp-Discovery.Read.All;
  • lists the Cloud Discovery streams you can access, or one you name;
  • pulls aggregated discovered-app data for a 7, 30 or 90 day period;
  • classifies each app as an AI product by name, domain, Defender for Cloud Apps category and keyword rules;
  • optionally looks up which users are associated with each app;
  • writes an app CSV, a user CSV and a self-contained HTML report, and opens the report in your browser unless you tell it not to.

It does not sanction, unsanction, block or change anything. The documentation says so explicitly, and the code only issues read requests to Graph.

Prerequisites

  • PowerShell. Windows PowerShell 5.1 or PowerShell 7. The script has a #requires -Version 5.1 line.
  • The Microsoft Graph authentication module. The script needs Connect-MgGraph, Invoke-MgGraphRequest, Get-MgContext and Disconnect-MgGraph. The documentation installs Microsoft.Graph.Authentication for that.
  • Admin consent. An administrator must grant consent to CloudApp-Discovery.Read.All, and the account you sign in with needs access to the Cloud Discovery data and streams.
  • Discovery data. At least one populated Cloud Discovery stream must exist. The script does not create or import discovery data. If you have not set up Cloud Discovery in Defender for Cloud Apps, there is nothing to report on.

That last point matters most for small business clients. Microsoft’s Defender for Cloud Apps getting started guide describes two main ways to feed discovery data. One is integrating with Microsoft Defender for Endpoint so Windows 10 and 11 devices are monitored, and the other is uploading firewall or proxy logs, either as a one-off snapshot report or through automatic log upload. I have not checked licensing for any of this. Confirm what your clients are entitled to before you promise them a report.

One more thing. The script uses the Microsoft Graph beta Cloud Discovery API, and its own header says the beta API can change and is not supported for production use. Microsoft documents the same endpoints on its discovered apps Graph API page. Treat the output as a point-in-time view and expect that field names may change.

Getting it and running it

This download snippet is my suggestion, built from the repository paths in the links above:

$dest = 'C:\Tools\ShadowAI'
New-Item -ItemType Directory -Path $dest -Force | Out-Null
$base = 'https://raw.githubusercontent.com/directorcia/Office365/master'
Invoke-WebRequest "$base/ai-shadow-report.ps1" -OutFile "$dest\ai-shadow-report.ps1"
Invoke-WebRequest "$base/ai-apps-catalog.json" -OutFile "$dest\ai-apps-catalog.json"
Unblock-File "$dest\ai-shadow-report.ps1"

Install-Module Microsoft.Graph.Authentication -Scope CurrentUser

Read the script before you run it. Then, from that folder:

.\ai-shadow-report.ps1

The default run uses a 30 day lookback and all the discovery streams you can access. It exports every discovered app, queries user associations where it can, uses ai-apps-catalog.json beside the script if it is there, and writes the reports into the script’s folder. It then opens the HTML report. Because the sign-in is interactive, a browser prompt will appear the first time. If your account has not been consented, ask a Global Administrator to approve the permission once.

Parameters

ParameterDefaultWhat it does
-Days30Lookback period. Only 7, 30 or 90 are accepted.
-StreamIdAll accessible streamsLimit the run to one discovery stream. An unknown or inaccessible ID stops the run.
-TenantIdCurrent context, or interactive selectionTenant ID or domain to sign in to.
-EnvironmentGlobalGraph cloud: Global, USGov or USGovDoD.
-OutputDirectoryThe script’s folderWhere the reports go. The folder must already exist.
-CatalogPathai-apps-catalog.json beside the scriptLocal AI catalog file.
-UpdateCatalogOffDownload the catalog first (HTTPS only), cache it if the path is writable, and fall back if that fails.
-CatalogUriThe catalog in the same GitHub repositoryHTTPS address used by -UpdateCatalog.
-AiOnlyOffExport only apps classified as Known or Possible AI, and skip user lookups for the rest.
-AiUsersOnlyOffExport all apps, but look up users only for AI-classified apps. Faster on large tenants.
-SkipUsersOffSkip user lookups. The user CSV has a header row only.
-NoLaunchOffSave the HTML report without opening it.
-PassThruOffReturn a summary object, including report paths, counts and warnings.
-WhatIf / -ConfirmThe script supports both. -WhatIf prevents the Graph connection and the export.

Examples

# AI-only app export over 30 days
.\ai-shadow-report.ps1 -Days 30 -AiOnly

# Refresh the AI catalog first
.\ai-shadow-report.ps1 -UpdateCatalog

# Look up users only for AI-classified apps
.\ai-shadow-report.ps1 -AiUsersOnly

# One stream, 90 days, no browser (the ID below is a placeholder)
.\ai-shadow-report.ps1 -Days 90 -StreamId "00000000-0000-0000-0000-000000000000" -NoLaunch

# Choose the output folder and capture a summary
$result = .\ai-shadow-report.ps1 -OutputDirectory "C:\Reports\ShadowAI" -NoLaunch -PassThru
[PSCustomObject]@{
    KnownAI    = $result.KnownAiAppCount
    PossibleAI = $result.PossibleAiAppCount
    Unsanctioned = $result.UnsanctionedAiCount
    Warnings   = $result.Warnings.Count
    Report     = $result.HtmlReportPath
}

# Preview without connecting
.\ai-shadow-report.ps1 -WhatIf

Create the output folder first. The script validates it and will not make one for you.

How it decides an app is AI

Each discovered app gets one of these classifications, based on the app name, its domains and its Defender for Cloud Apps category:

  • Known AI-capable product. The name or a domain matches a catalog product rule or a known AI domain, or the Defender category is one of the AI categories the script recognises: generativeAi, aiModelProvider, mcpServer and clientAiApp. The current built-in catalog (version 2026.11.30-builtin) has 74 product rules, plus a built-in list of known AI domains.
  • Possible AI product. No known match, but the catalog’s keyword pattern matched the app name or a domain. Terms such as generative AI and large language model are examples.
  • No AI match. Nothing matched.

The same catalog file is shared with the endpoint script. A custom catalog is a JSON file with a products array (each entry has a product and a pattern) and an optional keywordPattern. A custom entry replaces a built-in product of the same name, and new products are added. Both documents are clear that a match is evidence for investigation, not proof that a person used an AI feature or that anyone approved the app.

What you get

The app report

The app CSV and the HTML dashboard carry the same fields. The ones I look at first are:

  • AppName, Domains and Category, which is what the app is and where it lives.
  • AiConfidence, AiProducts and AiEvidence, which is the classification, the product it was matched to and the reason.
  • SanctionStatus and Tags, taken from the tags in Defender for Cloud Apps, as Sanctioned, Unsanctioned, Monitored or Not tagged.
  • RiskScore, the Defender risk score when it is available.
  • UserCount, IpAddressCount, TransactionCount and the upload and download bytes, which show how much the app is used.
  • StreamName, LogDataProvider and LastDataReceivedDateTime, which tell you which source the data came from and how fresh it is.

The user report

Unless you skip it, the script asks Graph which users are associated with each eligible app. It skips an app if its user count is zero, or its stream does not expose user names. The user CSV lists the app, its AI classification and sanction status, the risk score and the user identifier that Graph returned. The HTML report shows at most 500 user associations. The CSV is the complete export.

The HTML dashboard

The dashboard is a single offline file. It has summary cards (including exported apps, known AI, possible AI and unsanctioned AI), search and filters for confidence, sanction status and stream, sortable tables, CSV and JSON downloads of the visible rows, light and dark themes and print to PDF. It also lists stream coverage and any operational warnings, so read those before you trust the numbers.

Files are named with a millisecond timestamp, for example shadow-it-apps-yyyyMMdd-HHmmss-fff.csv, and the matching shadow-it-users and shadow-it-report files. The script stages files under temporary names and only publishes them after all three are generated. It will not overwrite an existing report. CSV values that start with a formula character are prefixed with an apostrophe, so opening them in a spreadsheet is safer.

Reading the results

  • Start with unsanctioned AI. Apps classified as AI and tagged Unsanctioned in Defender for Cloud Apps are the obvious first conversation. The script reports that count on the console and in the dashboard.
  • Then look at Not tagged. An AI app that nobody has tagged yet is exactly the shadow part. It tells you where your governance has not caught up.
  • Treat Possible matches as leads. Read the evidence column before you decide anything.
  • Never add up traffic across streams. Streams can overlap, so the same app may appear in more than one. The script and the documentation both warn about this.
  • Never divide app totals across users. The API provides app-level traffic only, not per-user traffic, so the numbers cannot tell you how much any one person sent.
  • Blank transfer fields are normal. Some sources do not provide volume information.

Running it regularly

The documentation does not describe scheduled or unattended use. The script signs in interactively with the delegated scope, and I could not find an app-only or certificate sign-in option in it. Everything in this section is my own suggestion and I have not tested it:

  • Run it monthly by hand, or as part of a client review, with -NoLaunch -PassThru and a dated output folder. Keep the reports so you can compare one month with the next.
  • Use -Days 30 for a monthly look and -Days 90 for a quarterly one, and keep the same stream selection each time so the numbers are comparable.
  • Compare the lists of AI apps month to month. New names and rising user counts are what matter. The tool does not do that comparison for you.
  • If you want a fully unattended job, you would need a sign-in method the script does not currently offer, so I would not try that without checking the code and the Graph permissions model first.

Privacy, limits and caveats

  • Reports are sensitive. They can contain tenant IDs, app names, domains, user identifiers, IP usage counts and traffic data. Store and share them in line with your privacy and retention requirements, and take particular care with the user CSV.
  • It only sees what discovery sees. The data comes from the selected streams and period. How complete that is depends on how discovery is set up for each client.
  • Classification is heuristic. Expect false positives and false negatives.
  • The API is beta. Field names and behaviour can change.
  • Your view depends on your role. A signed-in user sees only the data their tenant and Defender roles permit.
  • No enforcement. Sanctioning, blocking and policy all happen elsewhere, in Defender for Cloud Apps and your other controls.
  • Air-gapped environments. Skip -UpdateCatalog. The built-in catalog and a local catalog file still work.

How I would use it with clients

This is my view, not part of the script. I would run the endpoint inventory and the cloud discovery report together, and take both to the client as one story: here is what is installed, and here is what your network is actually reaching. The overlap is where the real shadow AI sits, and the gaps tell you where each tool is blind. From there the conversation is about policy. Which AI tools are approved, which are not, and who owns the decision. The reports give you the evidence. They do not give you the answer.

The takeaway

You do not need a new platform to start seeing shadow AI. If a client already has Defender for Cloud Apps discovery running, the data is sitting there, and one read-only script turns it into a report a business owner can read. If they do not, setting up discovery is the real first step. Either way, start with a pilot tenant, read the warnings and treat the first report as a baseline, not a verdict.

Sources (checked 1 December 2026)

Leave a Reply