Skip to content

Remove-MgmtGraphDevice

MgmtGraph: Deletes a Microsoft Graph device

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

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

Process {
    try {
        $params = @{
            'DeviceId'    = $Identity
            'Confirm'     = $false
            'ErrorAction' = 'Stop'
        }

        Remove-MgDevice @params
        
        $result = [PSCustomObject]@{
            DeviceId  = $Identity
            Action    = "DeviceRemoved"
            Status    = "Success"
            Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        }

        Write-Output $result
    }
    catch {
        throw
    }
}

Specifies the ID of the device to remove.

An interactive directory of PowerShell scripts.