🚀 Executive Summary

TL;DR: Intune’s “sticky” primary user assignment often causes policy application failures on re-assigned or shared devices. This guide offers solutions ranging from quick GUI fixes and scalable PowerShell scripts using the Microsoft Graph API to architectural strategies for shared device enrollment, preventing the issue proactively.

🎯 Key Takeaways

  • Intune’s primary user concept, while foundational for user-assigned policies, often clashes with operational realities like device re-assignment or shared usage, leading to policy application failures.
  • The Microsoft Graph API, accessible via PowerShell with the `Microsoft.Graph.Intune` module, enables programmatic management of Intune primary users, allowing for bulk assignment or removal using `Set-IntuneManagedDevice` or `Remove-IntuneManagedDeviceUser`.
  • Proactive architectural solutions for shared devices, such as “Shared multi-user device” profiles, Kiosk mode, or enrollment via a Device Enrollment Manager (DEM) account, are crucial to prevent the primary user problem entirely.

PowerShell 7 Script: Intune Primary User Management & Shared Device Handling

A senior engineer’s guide to fixing Intune’s stubborn primary user assignment with PowerShell and architectural best practices, turning a common helpdesk headache into a manageable, automated process.

Wrestling the Hydra: Taming Intune’s Primary User and Handling Shared Devices

I remember a frantic call on a Monday morning. Our head of sales, let’s call him “Bob,” couldn’t access a critical app on his new laptop. The policy wasn’t applying. We checked everything—groups, filters, license—all green. After 30 minutes of pulling our hair out, we checked the device’s primary user in Intune. It wasn’t Bob. It was “temp-it-01,” a temporary account used by the service desk tech who imaged the machine. Intune had latched onto that first user and refused to let go, blocking Bob’s user-assigned policies. We’ve all been there. It’s one of those “simple” problems that can derail a morning and highlights a fundamental challenge in how Intune thinks about devices vs. how we actually use them.

The “Why”: Intune’s Sticky User Syndrome

Before we dive into the fixes, let’s understand the root of the problem. By design, Intune wants a device to have a single primary user. This identity is used for app deployments, policy targeting, Company Portal enrollment, and reporting. When a user enrolls a device (especially through Autopilot or Company Portal), Intune often permanently stamps them as the primary user. The problem is, our world isn’t always one-to-one. Laptops get re-assigned, new hires get hand-me-downs, and we have shared devices on manufacturing floors or in conference rooms. Intune’s default “sticky” behavior just doesn’t account for the operational reality of IT.

Solution 1: The Quick & Dirty (The GUI Fix)

This is your go-to when you have a single, panicked user on the phone and you just need to solve it now. It doesn’t scale, but it’s effective for one-off emergencies.

  1. Navigate to the Microsoft Intune admin center.
  2. Go to Devices > All devices and find the problematic device.
  3. In the device’s Overview pane, you’ll see the current Primary user.
  4. Click Change primary user. A new pane will open where you can search for and select the correct user.
  5. You can also just click Remove primary user if the device should be treated as a shared machine with no specific owner.

This is fine for “Bob” from sales, but if you’re trying to clean up 50 devices after a departmental re-org, you’ll want to automate.

Solution 2: The Scalable Fix (The PowerShell Way)

When you need to fix this at scale, you break out PowerShell and the Microsoft Graph API. This is the real fix for sysadmins. First, make sure you have the necessary tools installed.

Install-Module Microsoft.Graph.Intune -Force
Connect-MgGraph -Scopes "DeviceManagementManagedDevices.ReadWrite.All"

Pro Tip: Be warned! The DeviceManagementManagedDevices.ReadWrite.All permission is powerful. In a production environment, you should be using a service principal or managed identity with precisely scoped permissions, not running this interactively with your global admin account.

Now, let’s look at a practical script. The goal here is to find a device and either change the primary user or remove them entirely.

# --- Script to Manage Intune Primary User ---

# Variables
$deviceName = "LPT-FIN-1138" # The device you're targeting
$newPrimaryUserUPN = "sandra.c@techresolve.com" # The UPN of the correct primary user

# 1. Find the Intune Device Object
Write-Host "Searching for device: $deviceName"
$device = Get-IntuneManagedDevice -Filter "deviceName eq '$deviceName'"
if (-not $device) {
    Write-Error "Device '$deviceName' not found. Exiting."
    return
}

# 2. Find the new user's Azure AD Object to get their ID
Write-Host "Searching for user: $newPrimaryUserUPN"
$user = Get-MgUser -Filter "userPrincipalName eq '$newPrimaryUserUPN'"
if (-not $user) {
    Write-Error "User '$newPrimaryUserUPN' not found. Exiting."
    return
}

# 3. Perform the Update
Write-Host "Setting '$newPrimaryUserUPN' as primary user for '$deviceName'..."
Set-IntuneManagedDevice -managedDeviceId $device.managedDeviceId -userPrincipalName $user.UserPrincipalName

Write-Host "Update command sent successfully."

# --- To REMOVE the primary user instead ---
# Uncomment the line below and comment out the 'Set-IntuneManagedDevice' line above
# Remove-IntuneManagedDeviceUser -managedDeviceId $device.managedDeviceId

# Write-Host "Primary user removal command sent successfully for '$deviceName'."

You can easily wrap this logic in a loop, reading from a CSV file of device names and new user UPNs to perform this in bulk. This is how you turn a day of clicking in a GUI into a 5-minute script run.

Solution 3: The ‘Nuclear’ Option (The Architect’s Answer)

Sometimes, the problem isn’t the primary user; it’s the fact that you’re trying to assign one at all. If a device is truly shared—a conference room PC, a factory floor kiosk, a loaner laptop pool—then it shouldn’t have a primary user. Fighting this is a losing battle.

The real, permanent fix is to enroll these devices differently from the start.

Method Use Case How It Works
Shared Multi-User Device Loaner laptops, classroom devices where different users log in with their own profiles. Use a “Shared multi-user device” configuration profile in Intune. This optimizes the device for multiple logins, manages profile cleanup, and prevents any single user from becoming “primary.”
Kiosk Mode Lobby check-in stations, inventory scanners, single-purpose machines. Use a Kiosk device configuration profile. This locks the device to one or more specific apps. No user truly “logs in” in a traditional sense, so the primary user concept is irrelevant.
Device Enrollment Manager (DEM) Account Bulk enrollment of devices that won’t have a primary user, like digital signage. Enroll devices using a DEM account. Devices enrolled this way are user-less by default, preventing the “first user” problem from ever occurring.

Choosing the right enrollment and configuration strategy from the beginning is the ultimate fix. It moves you from being a reactive firefighter to a proactive architect, which is where we all want to be. So next time you see this issue, fix it with the script, but then ask the bigger question: “Should this device have had a primary user in the first place?”

Darian Vance - Lead Cloud Architect

Darian Vance

Lead Cloud Architect & DevOps Strategist

With over 12 years in system architecture and automation, Darian specializes in simplifying complex cloud infrastructures. An advocate for open-source solutions, he founded TechResolve to provide engineers with actionable, battle-tested troubleshooting guides and robust software alternatives.


🤖 Frequently Asked Questions

âť“ What is the core problem with Intune’s primary user assignment for devices?

Intune’s default behavior assigns a single “sticky” primary user to a device, which can prevent user-assigned policies from applying correctly when devices are re-assigned or used by multiple individuals, leading to access issues.

âť“ How do the PowerShell and architectural solutions differ in managing Intune primary users?

The PowerShell solution (using Microsoft Graph API) is a reactive, scalable fix for existing devices to change or remove primary users. Architectural solutions (e.g., Shared multi-user device profiles, Kiosk mode, DEM accounts) are proactive strategies to prevent primary user assignment on truly shared devices from the outset.

âť“ What is a critical security best practice when using PowerShell for Intune primary user management?

When using PowerShell with the `DeviceManagementManagedDevices.ReadWrite.All` permission in a production environment, avoid interactive global admin accounts. Instead, utilize a service principal or managed identity with precisely scoped permissions to minimize security risks.

Leave a Reply

Discover more from TechResolve - SaaS Troubleshooting & Software Alternatives

Subscribe now to keep reading and get access to the full archive.

Continue reading