Hello Karim Ibrahim,
The following script changes the device category to unassigned. Hope this helps.
# Connect to MSGraph
Write-Host "Connecting to MSGraph..." -ForegroundColor Cyan
Update-MSGraphEnvironment -AppId 'xxxxxxxx-xxxx-xxxx-xxxxxxxxxxx'
Connect-MSGraph
function Unassign-DeviceCategory {
param(
[Parameter(Mandatory)]
[string]$DeviceID,
[Parameter(Mandatory)]
[string]$DeviceCategory
)
$body = @{ "@odata.id" = "https://graph.microsoft.com/beta/deviceManagement/deviceCategories/$DeviceCategory" }
Invoke-MSGraphRequest -HttpMethod PUT -Url "deviceManagement/managedDevices/$DeviceID/deviceCategory/`$ref" -Content $body
}
$DeviceID = 'xxxxxxxx-xxxx-xxxx-xxxxxxxxxxx'
$DeviceCategory = '00000000-0000-0000-0000-000000000000'
Unassign-DeviceCategory -DeviceID $DeviceID -DeviceCategory $DeviceCategory
If you found the information above helpful, please Accept the answer. This will assist others in the community who encounter a similar issue, enabling them to quickly find the solution and benefit from the guidance provided.