HomeNewsletterCommunityToolsArchiveBlogAboutQuick Links Subscribe free
← Back to Blog
Intune PowerShellMicrosoft GraphIntuneAutomationDevice ManagementScripting

Top 10 Intune PowerShell Commands Every Admin Should Know

IA
Imran Awan
27 June 2026

If you manage Intune at scale, PowerShell with Microsoft Graph is your most important tool. These 10 commands are the foundation every IT admin, EUC engineer, and Modern Workplace engineer needs before moving to advanced automation. Master these and you can handle device inventory, compliance reporting, remote actions, and cleanup — all from the terminal.

Prerequisites

Install the Microsoft Graph PowerShell SDK if you have not already. Run this once in an elevated PowerShell session:

Install-Prerequisites.ps1
# Install the Microsoft Graph module (run once, elevated)
Install-Module Microsoft.Graph -Scope CurrentUser

# Import for the current session
Import-Module Microsoft.Graph

Requires PowerShell 5.1 or PowerShell 7+. The module works in Windows PowerShell, PowerShell Core, and the VS Code terminal. Official docs: Microsoft Graph PowerShell SDK overview.

1. Connect to Microsoft Graph

Every Intune automation script starts here. This authenticates your session and defines which Graph API permissions you are requesting.

01-Connect.ps1
Connect-MgGraph -Scopes "DeviceManagementManagedDevices.ReadWrite.All", "Directory.Read.All"

This opens a browser window for interactive sign-in. For unattended automation (scheduled tasks, Azure Automation), use a service principal with app-only permissions instead. Without a successful connection, all downstream commands will fail with an authentication error. See: Connect-MgGraph authentication.

2. Get All Managed Devices

Returns every device enrolled in Intune. Use this as the starting point for any inventory, reporting, or bulk operation.

02-GetAllDevices.ps1
Get-MgDeviceManagementManagedDevice

Returns objects with properties including DeviceName, UserPrincipalName, ComplianceState, OperatingSystem, LastSyncDateTime, and more. Pipe to Select-Object or Where-Object to filter. Reference: Get-MgDeviceManagementManagedDevice.

3. Get a Specific Device

Filter by device name for targeted troubleshooting or support work.

03-GetSpecificDevice.ps1
Get-MgDeviceManagementManagedDevice |
  Where-Object {$_.DeviceName -eq "LAPTOP-001"}

For large tenants, retrieving all devices before filtering is slow. Use the -Filter parameter to push filtering to the Graph API instead:

03-GetSpecificDevice-Efficient.ps1
Get-MgDeviceManagementManagedDevice -Filter "deviceName eq 'LAPTOP-001'"

4. Export Devices to CSV

Build audit-ready reports or feed data into Excel, Power BI, or a ticketing system.

04-ExportDevices.ps1
Get-MgDeviceManagementManagedDevice |
  Select-Object DeviceName, UserPrincipalName, ComplianceState, OperatingSystem, LastSyncDateTime |
  Export-Csv "C:\Temp\IntuneDevices.csv" -NoTypeInformation

Add -Encoding UTF8 if you are sharing the CSV with teams on different locales to avoid character encoding issues.

5. Get Non-Compliant Devices

The most important command for security operations. Returns every device that is currently failing compliance policy.

05-NonCompliantDevices.ps1
Get-MgDeviceManagementManagedDevice |
  Where-Object {$_.ComplianceState -ne "compliant"} |
  Select-Object DeviceName, UserPrincipalName, ComplianceState, LastSyncDateTime |
  Export-Csv "C:\Temp\NonCompliant.csv" -NoTypeInformation

ComplianceState values include compliant, noncompliant, unknown, conflict, and error. Filtering for anything other than compliant catches all risk states. See: Monitor Intune device compliance policies.

6. Force Sync a Device

When a policy change is not reaching a device, or a user reports Intune settings are not applying, force a sync without waiting for the next scheduled check-in.

06-ForceSync.ps1
# Get the device ID first
$device = Get-MgDeviceManagementManagedDevice -Filter "deviceName eq 'LAPTOP-001'"

# Trigger sync
Invoke-MgDeviceManagementManagedDeviceSyncDevice -ManagedDeviceId $device.Id

The sync request is queued and delivered when the device next communicates with Intune — it is not instant if the device is offline. Reference: Sync devices with Intune.

7. Restart a Device Remotely

Remote reboot without RDP. Useful after policy changes that require a restart, or during troubleshooting when the user is unavailable.

07-RemoteReboot.ps1
$device = Get-MgDeviceManagementManagedDevice -Filter "deviceName eq 'LAPTOP-001'"

Invoke-MgDeviceManagementManagedDeviceRebootNow -ManagedDeviceId $device.Id

The device must be online and able to receive the command from Intune. The user will see a notification before the reboot occurs. Reference: Remotely restart devices with Intune.

8. Wipe a Device Remotely

Factory reset a device over the air — the most critical remote action for lost, stolen, or employee exit scenarios.

08-WipeDevice.ps1
$device = Get-MgDeviceManagementManagedDevice -Filter "deviceName eq 'LAPTOP-001'"

Invoke-MgDeviceManagementManagedDeviceWipe -ManagedDeviceId $device.Id `
  -KeepEnrollmentData:$false `
  -KeepUserData:$false

Warning: this is irreversible. Set -KeepEnrollmentData:$true if you want the device to automatically re-enrol into Autopilot after the wipe. Set -KeepUserData:$true for a selective wipe that removes corporate data only (for BYOD). Reference: Remove devices by using wipe, retire, or manually unenrolling the device.

9. Delete a Stale Device Record

Removes the device object from Intune. Use this for devices that are already decommissioned, reset, or no longer exist — not as a substitute for wipe on active devices.

09-DeleteDevice.ps1
$device = Get-MgDeviceManagementManagedDevice -Filter "deviceName eq 'LAPTOP-OLD'"

Remove-MgDeviceManagementManagedDevice -ManagedDeviceId $device.Id

For bulk cleanup of devices inactive for 90+ days, combine with a LastSyncDateTime filter:

09-BulkDeleteStaleDevices.ps1
$cutoff = (Get-Date).AddDays(-90)

Get-MgDeviceManagementManagedDevice |
  Where-Object { $_.LastSyncDateTime -lt $cutoff } |
  ForEach-Object {
    Write-Host "Removing: $($_.DeviceName) — last sync $($_.LastSyncDateTime)"
    Remove-MgDeviceManagementManagedDevice -ManagedDeviceId $_.Id
  }

10. Get Device Last Sync Time

Identify devices that have gone dark — not communicating with Intune. Essential for identifying stale records, offline devices, and potential security gaps.

10-LastSyncTime.ps1
Get-MgDeviceManagementManagedDevice |
  Select-Object DeviceName, UserPrincipalName, LastSyncDateTime |
  Sort-Object LastSyncDateTime |
  Export-Csv "C:\Temp\LastSync.csv" -NoTypeInformation

Sorting ascending puts the most outdated devices at the top, making it easy to spot devices that have not synced in weeks or months.

Bonus: Bulk Wipe Script

This pattern iterates all managed devices and wipes each one. Only use this in decommission or emergency scenarios — it is irreversible across your entire fleet.

BulkWipe.ps1
# CAUTION: wipes every device in the array — test in a lab first
$devices = Get-MgDeviceManagementManagedDevice

foreach ($device in $devices) {
  Invoke-MgDeviceManagementManagedDeviceWipe `
    -ManagedDeviceId $device.Id `
    -KeepEnrollmentData:$false `
    -KeepUserData:$false
  Write-Host "Wipe initiated for $($device.DeviceName)" -ForegroundColor Green
}

Best Practices

Official Resources

Share this post
LinkedIn X / Twitter Reddit Bluesky

More from EndpointWeekly

Scripts
Get the Primary User and Last Sync Time for Any Intune Device —…
You export a list of devices and all you get is hostnames. This script feeds that CSV…
Intune
Microsoft Intune: Win32 vs. Store App Deployment — Complete Guide
Win32 or Store? Complete breakdown of both Intune app deployment methods — packaging, IME…
Intune
Intune and Apple WWDC 2026 — What IT Admins Need to Know
Apple WWDC 2026 brought major changes to MDM management — new declarative device…