---
title: How to Use Get-MgDevice in PowerShell
meta_title: Get-MgDevice PowerShell Guide with Examples
slug: get-mgdevice-powershell
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T00:00:00.000Z
feature_image: /blog/images/get-mgdevice-powershell/get-mgdevice-syntax-microsoft-learn.1600.webp
feature_image_alt: Microsoft Learn documentation for the Get-MgDevice cmdlet showing its PowerShell syntax
author: James Futhey
author_slug: james
meta_description: Get-MgDevice lists devices registered in Microsoft Entra ID through Microsoft Graph. Examples to filter, search, count, find stale devices and export to CSV.
status: published
---

## Quick answer

`Get-MgDevice` lists the device objects registered in your organization's Microsoft Entra ID. Connect with a device read permission, then run it:

```powershell
Connect-MgGraph -Scopes 'Device.Read.All'
Get-MgDevice -All
```

For one device, pass its object ID:

```powershell
Get-MgDevice -DeviceId "6fa60d52-01e7-4b18-8055-4759461fc16b"
```

It's in the `Microsoft.Graph.Identity.DirectoryManagement` module. See [Connect-MgGraph](/blog/use-connect-mggraph-powershell/) if you can't connect.

## What does Get-MgDevice do?

It reads device objects from Microsoft Graph. It doesn't change anything. It has three forms:

| Form | Parameter | Returns |
|---|---|---|
| List (default) | `-Filter`, `-Search`, `-Top`, `-All` and others | Many devices |
| Get | `-DeviceId` | One device |
| GetViaIdentity | `-InputObject` | One device |

A device has two IDs, and they're easy to mix up:

| Property | What it is |
|---|---|
| `id` | The object's unique identifier in the directory |
| `deviceId` | An identifier set by the Azure Device Registration Service when the device registered |

`-DeviceId` takes the object `id`. To look a device up by its `deviceId` property, filter on it:

```powershell
Get-MgDevice -Filter "deviceId eq '00000000-0000-0000-0000-000000000000'"
```

## Which permission does it need?

| Permission type | Least privileged | Higher privileged |
|---|---|---|
| Delegated (work or school account) | `Device.Read.All` | `Directory.Read.All`, `Directory.ReadWrite.All` |
| Delegated (personal Microsoft account) | Not supported | Not supported |
| Application | `Device.Read.All` | `Device.ReadWrite.All`, `Directory.Read.All`, `Directory.ReadWrite.All` |

With delegated access, the signed-in user also needs a supported Microsoft Entra role, such as Directory Readers, Global Reader or Device Managers.

## Examples

| Goal | Command |
|---|---|
| Every device | `Get-MgDevice -All` |
| One device by object ID | `Get-MgDevice -DeviceId $id` |
| One device by name | `Get-MgDevice -Filter "displayName eq 'PC01'"` |
| Names that start with a word | `Get-MgDevice -Filter "startswith(displayName, 'Conf')" -All` |
| Android devices | `Get-MgDevice -Filter "operatingSystem eq 'Android'" -All` |
| Disabled devices | `Get-MgDevice -Filter "accountEnabled eq false" -All` |
| Compliant devices | `Get-MgDevice -Filter "isCompliant eq true" -All` |
| Entra joined devices | `Get-MgDevice -Filter "trustType eq 'AzureAd'" -All` |
| Only some properties | `Get-MgDevice -All -Property "id,displayName,operatingSystem"` |
| Count every device | `Get-MgDevice -All -ConsistencyLevel eventual -CountVariable n` then `$n` |

## Why don't I get every device?

`-All` lists all pages. Without it you get only the first page of results. Add `-All` to every list, count or export that should cover the whole tenant.

`-Top` does the opposite: it returns only the first n devices.

## How do I filter devices?

`-Filter` takes an OData filter. These properties are the most useful:

| Property | Filter operators |
|---|---|
| `displayName` | `eq`, `ne`, `not`, `ge`, `le`, `in`, `startsWith`, eq on null |
| `operatingSystem` | `eq`, `ne`, `not`, `ge`, `le`, `startsWith`, eq on null |
| `operatingSystemVersion` | `eq`, `ne`, `not`, `ge`, `le`, `startsWith`, eq on null |
| `accountEnabled` | `eq`, `ne`, `not`, `in` |
| `isCompliant` | `eq`, `ne`, `not` |
| `isManaged` | `eq`, `ne`, `not` |
| `trustType` | `eq`, `ne`, `not`, `in` |
| `deviceId` | `eq`, `ne`, `not`, `startsWith` |
| `approximateLastSignInDateTime` | `eq`, `ne`, `not`, `ge`, `le`, eq on null |

`trustType` is one of `Workplace` (personal devices people bring), `AzureAd` (cloud-only joined) or `ServerAd` (on-premises domain joined devices joined to Microsoft Entra ID). Only Intune, or an approved MDM app on Windows, updates `isCompliant` and `isManaged`.

Some queries need advanced query parameters: `-ConsistencyLevel eventual` and `-CountVariable`. That includes `-Search`, the `ne` and `not` operators, and counts. Microsoft's own example:

```powershell
Get-MgDevice -Filter "startswith(displayName, 'a')" -CountVariable CountVar -Top 1 -Sort "displayName" -ConsistencyLevel eventual
```

## How do I search for a device?

`-Search` matches words in the display name. It needs the advanced query parameters, and the search string goes in double quotes inside single quotes:

```powershell
Get-MgDevice -Search '"displayName:Android"' -CountVariable CountVar -ConsistencyLevel eventual
```

## How do I find stale devices?

`approximateLastSignInDateTime` holds the approximate time the device last signed in, in UTC. Filter on it with `le` and an ISO 8601 date:

```powershell
Get-MgDevice -All -Filter "approximateLastSignInDateTime le 2026-05-01T00:00:00Z" -ConsistencyLevel eventual -CountVariable n |
  Select-Object DisplayName,OperatingSystem,ApproximateLastSignInDateTime
```

Check the list before you disable or delete anything.

## How do I export devices to CSV?

Pick the columns, then write the file:

```powershell
Get-MgDevice -All |
  Select-Object DisplayName,OperatingSystem,OperatingSystemVersion,TrustType,AccountEnabled,ApproximateLastSignInDateTime |
  Export-Csv devices.csv -NoTypeInformation
```

## Why doesn't Get-MgDevice work?

| Symptom | Likely cause | Fix |
|---|---|---|
| The term Get-MgDevice isn't recognized | The module isn't installed | Run `Install-Module Microsoft.Graph.Identity.DirectoryManagement -Scope CurrentUser` |
| Insufficient privileges | The session lacks a device read permission, or the user lacks a supported role | Reconnect with `Connect-MgGraph -Scopes 'Device.Read.All'` and check the user's Entra role |
| Only some devices come back | No `-All` | Add `-All` |
| A filter with `ne` or `not` fails | It needs advanced query parameters | Add `-ConsistencyLevel eventual -CountVariable n` |
| `-Search` fails | It needs advanced query parameters | Add `-ConsistencyLevel eventual -CountVariable n` |
| `-DeviceId` can't find a device | You passed the `deviceId` property, not the object `id` | Filter with `-Filter "deviceId eq '...'"` instead |
| It fails with a personal Microsoft account | Personal accounts aren't supported | Sign in with a work or school account |

## How do I check the result?

Count the devices, then look at one you know:

```powershell
Get-MgDevice -All -ConsistencyLevel eventual -CountVariable n | Out-Null
$n
Get-MgDevice -Filter "displayName eq 'PC01'" | Format-List DisplayName,Id,DeviceId,OperatingSystem,TrustType,AccountEnabled
```

## Sources

- [Get-MgDevice](https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.identity.directorymanagement/get-mgdevice) on Microsoft Learn
- [List devices](https://learn.microsoft.com/en-us/graph/api/device-list?view=graph-rest-1.0) on Microsoft Learn
- [Get device](https://learn.microsoft.com/en-us/graph/api/device-get?view=graph-rest-1.0) on Microsoft Learn
- [device resource type](https://learn.microsoft.com/en-us/graph/api/resources/device?view=graph-rest-1.0) on Microsoft Learn
- [Advanced query capabilities on directory objects](https://learn.microsoft.com/en-us/graph/aad-advanced-queries) on Microsoft Learn

Meeting Room 365 turns any iPad or Android tablet into a room display for Exchange and Microsoft 365 calendars. See the [features](/features/) or [pricing](/pricing/): $9 a room a month.
