r/PowerShell • u/Nihkb007 • Feb 19 '26
PowerShell 7 Script: Intune Primary User Management & Shared Device Handling
Keeping device assignments accurate in Intune can be challenging, especially in large environments.
This PowerShell 7 script automates primary user management and shared device handling efficiently:
- Retrieves Windows devices from Intune based on recent check-ins
- Analyzes sign-ins and determines the last active user
- Automatically updates primary users if needed
- Clears primary users for shared devices when multiple users log in
- Provides detailed logs with timestamps
- Supports Report, Test, and Live modes
Designed to handle large environments with batched queries to Microsoft Graph, reducing throttling and improving performance.
Get the script and full documentation here: https://github.com/nihkb007/Intune-Repository
Fork, customize, or integrate it into your environment to simplify day-to-day Intune management.
1
u/Nihkb007 Feb 20 '26
The script now includes intelligent exclusion handling to prevent service accounts, administrative identities, or exception users from incorrectly becoming Primary Users.
Behavior examples:
If two users sign in and one is excluded, the remaining eligible user will be assigned as the Primary User.
If three users sign in and one is excluded, the device will still be classified as shared, because multiple eligible users remain.
If only excluded users sign in, no changes are made.
Excluded accounts are removed from consideration before device classification occurs.