Skip to content

Deploy Homebrew with Microsoft Intune

Roll Homebrew out to your Macs with one Intune shell script, let standard users install packages without admin rights, and scope package policy to your Entra ID groups.

One shell script installs Homebrew and EnterpriseBrew

Intune runs the install script as root when Run script as signed-in user is set to No. On each Mac the script installs Apple's Command Line Tools if they're missing, installs Homebrew from your EnterpriseBrew server (or keeps the copy that's already there), adds the EnterpriseBrew CLI and enrolls the Mac with your workspace's enrollment key. Nobody signs in to EnterpriseBrew on the Mac and nobody types a password.

Homebrew is set up for whoever is signed in at the screen, and the script works that out itself. A Mac at the login window or still in Setup Assistant has nobody to set Homebrew up for, so the run fails and Intune tries again the next day. For a build machine that nobody signs in to, you name the account in the script.

Set it to run every day: a Mac that's already set up exits before anything is downloaded, so the daily run only does work on new Macs and on ones nobody was signed in to last time.

Every brew install on an enrolled Mac is then decided on the server: your allow and block rules, license rules and minimum versions apply, the package is checked against the best available vulnerability data, and the install is logged under the person and the Mac.

Homebrew for standard users

Homebrew's own installer needs an administrator, and developers on standard accounts don't have one. That's why so many admins end up writing their own Intune script for it. Here the steps that need root happen inside the Intune script, and the Homebrew prefix is handed to the person who will use it. They run brew install without sudo and without a local admin account.

If you'd rather the developer didn't own the prefix at all, turn on managed brew. The prefix then belongs to a local service account, and brew install still works without a password: the CLI passes the command to that account through a narrow sudoers rule, and the server still checks every package. Calling Homebrew directly to get around EnterpriseBrew doesn't get far, because the developer can't write to the prefix and Homebrew refuses before it changes anything.

Casks that ship a macOS installer package need real root. In managed mode those are left to IT unless you turn on privileged installs, which let the service account run the cask's installer. What may be installed is still your policy's decision.

Entra ID groups become device groups

Register an app in Microsoft Entra with three read-only Microsoft Graph application permissions (DeviceManagementManagedDevices.Read.All, Device.Read.All and GroupMember.Read.All) and grant admin consent. EnterpriseBrew then reads your Intune Macs every 15 minutes, together with the Entra ID groups each Mac's device object is in, nested groups included. Those are the groups you already assign Intune policies and apps to, and they show up as device groups for allow and block rules, package sets, Brew configurations and remote commands.

It's the device's groups that count, not the user's. A Mac with no Entra device registration, for example one enrolled without a user or one where nobody has signed in to Company Portal, is in no group. For those Macs, use a manual device group: download its configuration profile and assign it in Intune, or add the Macs by serial number.

Membership follows Entra. When a Mac leaves a group, the next sync takes it out of the device group, and the rules scoped to that group stop applying to it. If a sync fails, or Intune suddenly reports no Macs at all, EnterpriseBrew keeps the last known groups.

The daily check-in

A second, optional script runs the check-in once a day with the same settings. It lists the Mac under MDM Devices even without the API connection, enrolls a Mac the install script couldn't, and installs a waiting CLI update on a Mac whose own updater is missing. It downloads nothing to run.

Before it runs the CLI as root, the script hashes the file with tools from /usr/bin and compares the result with the CLI versions your server has published. A file that matches none of them isn't run: the script reports it, exits with an error that Intune shows, and the Mac's page in the portal shows the finding. That's evidence the file was changed. It doesn't stop someone with admin rights from changing it.

Rollout in steps

  1. 1

    Download the install script

    In the EnterpriseBrew portal, open Device Enrollment, choose Microsoft Intune and activate it. Download the install script, already filled in for your workspace.

  2. 2

    Add it to Intune

    In the Intune admin center, go to Devices > By platform > macOS > Manage devices > Scripts and add a script called EnterpriseBrew Install.

  3. 3

    Set how it runs

    Run script as signed-in user: No. Hide script notifications on devices: Yes. Script frequency: Every 1 day. Max number of times to retry if script fails: 3 times. Assign it to a Mac-only pilot group first.

  4. 4

    Connect Microsoft Graph

    Register an app in Entra, create a client secret and add the three application permissions with admin consent. Enter the tenant ID, the client ID and the secret's value on Device Enrollment, then save and sync.

  5. 5

    Check, then widen the assignment

    Intune's agent picks up new scripts at its own check-in, which can be hours away; Company Portal > the device > Check settings brings it forward. The Mac then shows up under Machines and its groups under Device Groups.

What syncs from Intune

The Graph connection is read-only and runs every 15 minutes. Sync now on Device Enrollment runs it straight away.

WhatHow it's used
MacsEvery Intune managed device running macOS, with its device name and serial number. The serial matches it to the Mac that enrolled.
Entra ID groupsThe groups each Mac's device object is in, nested ones included, kept as read-only device groups. Directory roles and administrative units are left out.
OwnerThe primary user's email, which installs from that Mac are recorded under. Until the API is connected, they're recorded as device:<hostname>.
Written back to IntuneNothing. All three Graph permissions are read permissions.

Limits worth knowing

  • Someone has to be signed in when the script runs, or the script has to name the account. Homebrew set up for root is of no use to the person who signs in later.
  • Intune's script agent needs macOS 12 or later and doesn't work through a proxy, so the Macs need a direct route to the internet.
  • Scripts reach a Mac at the agent's own check-in, up to 8 hours apart.
  • Only the device's Entra groups are read. A Mac without an Entra device registration is in none of them until you place it another way.
  • The client secret expires on the date Entra shows. Once it lapses, the sync stops until you enter a new one.
  • Entra groups are read-only in EnterpriseBrew. A manual device group with the same name keeps the Entra group out, and the sync result names it.
  • The admin center shows only whether a script succeeded. On the Mac, the agent's log under /Library/Logs/Microsoft/Intune records each run and its exit code.
  • The Macs need to reach your EnterpriseBrew server and formulae.brew.sh, where Homebrew reads its package metadata.

Further reading