You can use the Graph API List device groups method in PowerShell. Please view the following code for reference.
Install-Module -Name Microsoft.Graph
Connect-Graph -Scopes "User.Read.All", "Group.ReadWrite.All", "Device.Read.All"
$DeviceGroupData = Invoke-GraphRequest -Uri "https://graph.microsoft.com/v1.0/devices/<deviceid>/memberOf"
$DeviceGroupData.value.displayName
Please replace the <deviceid> with the real one.
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.