Skip to content

Get-MgmtGraphDevice

MgmtGraph: Audits Microsoft Graph devices

#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Identity.DirectoryManagement

[CmdletBinding()]
Param (
    [Parameter(Position = 0)]
    [string]$Identity
)

Process {
    try {
        $params = @{
            'ErrorAction' = 'Stop'
        }

        if ($Identity) {
            $params.Add('DeviceId', $Identity)
        }
        else {
            $params.Add('All', $true)
        }

        $devices = Get-MgDevice @params
        
        $results = foreach ($d in $devices) {
            [PSCustomObject]@{
                DisplayName     = $d.DisplayName
                Id              = $d.Id
                DeviceId        = $d.DeviceId
                OS              = $d.OperatingSystem
                OSVersion       = $d.OperatingSystemVersion
                AccountEnabled  = $d.AccountEnabled
                IsCompliant     = $d.IsCompliant
                TrustType       = $d.TrustType
                Timestamp       = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
            }
        }

        Write-Output ($results | Sort-Object DisplayName)
    }
    catch {
        throw
    }
}

Optional. Specifies the ID of the device to retrieve. If omitted, all devices are listed.

An interactive directory of PowerShell scripts.