Home

Managing Intune Device Categories via Powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-361136%22%20slang%3D%22en-US%22%3EManaging%20Intune%20Device%20Categories%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-361136%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3ELooking%20for%20a%20bit%20of%20help%20with%20the%20Intune%20Powershell%2Fgraph%20interface.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20trying%20to%20manipulate%20Intune%20Device%20Categories%20via%20Powershell%2C%20so%20that%20I%20can%20firstly%20correct%20devices%20that%20were%20placed%20into%20the%20wrong%20category%20during%20enrollment%2C%20and%20secondly%2C%20I'm%20in%20the%20middle%20of%20moving%20from%20Hybrid%20SCCM%2FIntune%20to%20Azure%20Intune%20and%20where%20we're%20not%20using%20Device%20Categories%20for%20devices%20already%20enrolled%20into%20SCCM%20Hybrid%20Intune%2C%20I%20want%20to%20use%20powershell%20to%20loop%20through%20a%20CSV%20file%20full%20of%20device%20serial%20numbers%20%2F%20IMEI%20numbers%20and%20place%20corporate%20devices%20into%20the%20right%20device%20category.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%2C%20investigating%20the%20powershell%2Fgraph%20interface%20for%20Intune%2C%20I%20can%20do%20something%20like%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3EGet-IntuneManagedDevice%20-Filter%20%22IMEI%20eq%20'01%20012345%20678910%201'%22%3C%2FEM%3E%20(Or%20-Filter%20%22serialNumber%20eq%20'DEADBEEF'%22%20or%20whatever)%20and%20get%20my%20all%20my%20device's%20details%20output.%26nbsp%3BThis%20includes%20a%20field%20for%20%22deviceCategoryDisplayName%22%2C%20which%20is%20the%20value%20I%20want%20to%20change.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can%20even%20do%26nbsp%3B%3CEM%3EGet-IntuneManagedDevice%20-Filter%20%22serialNumber%20eq%20'DEADBEEF'%22%7C%20select%20manageddeviceid%3C%2FEM%3E%20to%20get%20the%20managedDeviceID%20value%20as%20an%20output.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20far%20as%20I%20can%20tell%2C%20this%20should%20work%20with%20Update-IntuneManagedDevice%3F%20(see%20below)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3Eget-help%20Update-IntuneManagedDevice%20-detailed%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CEM%3ENAME%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3EUpdate-IntuneManagedDevice%3C%2FEM%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CEM%3ESYNOPSIS%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3EUpdates%20a%20%22microsoft.graph.managedDevice%22.%3C%2FEM%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CEM%3ESYNTAX%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3EUpdate-IntuneManagedDevice%20-managedDeviceId%20%3CSTRING%3E%3C%2FSTRING%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20I%20should%20be%20able%20to%20update%20a%20device%20by%20using%20its%20managed%20Device%20ID%3F%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I%20%3CSTRONG%3Ecan't%3C%2FSTRONG%3E%20do%20is%3A%3C%2FP%3E%3CP%3EGet-IntuneManagedDevice%20-Filter%20%22serialNumber%20eq%20'deadbeef'%22%7C%20select%20manageddeviceid%20%7C%20Update-IntuneManagedDevice%20-deviceCategoryDisplayName%20'BYOD'%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20get%20the%20error%20below.%20Clearly%20I'm%20doing%20something%20wrong%20but%20can%20anyone%20point%20me%20in%20the%20right%20direction%3F%20I%20don't%20think%20that%20what%20I'm%20trying%20to%20do%20is%20fundamentally%20unreasonable...%20is%20it%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(just%20to%20be%20clear%2C%20doing%26nbsp%3B%3CEM%3EGet-IntuneManagedDevice%20-managedDeviceID%20deadbeef-aaaa-bbbb-cccc-0123456789ab%26nbsp%3B%3C%2FEM%3E%20returns%20my%20target%20device%20details%20ok%2C%20and%20running%26nbsp%3B%3CEM%3EUpdate-IntuneManagedDevice%20-managedDeviceID%20deadbeef-aaaa-bbbb-cccc-0123456789ab%20-deviceCategoryDisplayName%20'BYOD'%3C%2FEM%3E%20gives%20me%20the%20same%20error)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUpdate-IntuneManagedDevice%20%3A%20400%20Bad%20Request%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%22error%22%3A%20%7B%3CBR%20%2F%3E%22code%22%3A%20%22InternalError%22%2C%3CBR%20%2F%3E%22message%22%3A%20%22%7B%5Cr%5Cn%20%5C%22_version%5C%22%3A%203%2C%5Cr%5Cn%20%5C%22Message%5C%22%3A%20%5C%22An%20error%20has%20occurred%20-%20Operation%20ID%20(for%20customer%20support)%3A%2000000000-0000-0000-0000-000000000000%20-%20Activity%20ID%3A%206f743002-b0e0-48ed-a25d-0cdd33870efd%20-%20Url%3A%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ffef.msub02.manage.microsoft.com%2FDeviceFE%2FStatelessDeviceFEService%2FdeviceManagement%2FmanagedDevices%2528%2527cef75e9c-9747-4520-8e18-2498ac18a1da%2527%2529%3Fapi-version%3D2018-05-24%5C%26quot%3B%2C%5Cr%5Cn%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Ffef.msub02.manage.microsoft.com%2FDeviceFE%2FStatelessDeviceFEService%2FdeviceManagement%2FmanagedDevices%2528%2527cef75e9c-9747-4520-8e18-2498ac18a1da%2527%2529%3Fapi-version%3D2018-05-24%5C%22%2C%5Cr%5Cn%3C%2FA%3E%20%5C%22CustomApiErrorPhrase%5C%22%3A%3CBR%20%2F%3E%5C%22%5C%22%2C%5Cr%5Cn%20%5C%22RetryAfter%5C%22%3A%20null%2C%5Cr%5Cn%20%5C%22ErrorSourceService%5C%22%3A%20%5C%22%5C%22%2C%5Cr%5Cn%20%5C%22HttpHeaders%5C%22%3A%20%5C%22%7B%7D%5C%22%5Cr%5Cn%7D%22%2C%3CBR%20%2F%3E%22innerError%22%3A%20%7B%3CBR%20%2F%3E%22request-id%22%3A%20%226f743002-b0e0-48ed-a25d-0cdd33870efd%22%2C%3CBR%20%2F%3E%22date%22%3A%20%222019-03-06T14%3A08%3A02%22%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3EAt%20line%3A1%20char%3A92%3CBR%20%2F%3E%2B%20...%20ddeviceid%20%7C%20Update-IntuneManagedDevice%20-deviceCategoryDisplayName%20'BY%20...%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20ConnectionError%3A%20(%40%7BRequest%3D%3B%20Response%3D%7D%3APSObject)%20%5BUpdate-IntuneManagedDevice%5D%2C%20HttpRequestException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20PowerShellGraphSDK_HttpRequestError%2CMicrosoft.Intune.PowerShellGraphSDK.PowerShellCmdlets.Update_IntuneManagedDevice%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-361136%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EGraph%20API%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIntune%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Robert Moir
New Contributor

Hi all,

Looking for a bit of help with the Intune Powershell/graph interface.

 

I'm trying to manipulate Intune Device Categories via Powershell, so that I can firstly correct devices that were placed into the wrong category during enrollment, and secondly, I'm in the middle of moving from Hybrid SCCM/Intune to Azure Intune and where we're not using Device Categories for devices already enrolled into SCCM Hybrid Intune, I want to use powershell to loop through a CSV file full of device serial numbers / IMEI numbers and place corporate devices into the right device category.

 

So, investigating the powershell/graph interface for Intune, I can do something like 

 

Get-IntuneManagedDevice -Filter "IMEI eq '01 012345 678910 1'" (Or -Filter "serialNumber eq 'DEADBEEF'" or whatever) and get my all my device's details output. This includes a field for "deviceCategoryDisplayName", which is the value I want to change.

 

I can even do Get-IntuneManagedDevice -Filter "serialNumber eq 'DEADBEEF'"| select manageddeviceid to get the managedDeviceID value as an output.

 

As far as I can tell, this should work with Update-IntuneManagedDevice? (see below)

 

get-help Update-IntuneManagedDevice -detailed

NAME
Update-IntuneManagedDevice

SYNOPSIS
Updates a "microsoft.graph.managedDevice".

SYNTAX
Update-IntuneManagedDevice -managedDeviceId <string>

 

So I should be able to update a device by using its managed Device ID? 

What I can't do is:

Get-IntuneManagedDevice -Filter "serialNumber eq 'deadbeef'"| select manageddeviceid | Update-IntuneManagedDevice -deviceCategoryDisplayName 'BYOD'

 

I get the error below. Clearly I'm doing something wrong but can anyone point me in the right direction? I don't think that what I'm trying to do is fundamentally unreasonable... is it?

 

(just to be clear, doing Get-IntuneManagedDevice -managedDeviceID deadbeef-aaaa-bbbb-cccc-0123456789ab  returns my target device details ok, and running Update-IntuneManagedDevice -managedDeviceID deadbeef-aaaa-bbbb-cccc-0123456789ab -deviceCategoryDisplayName 'BYOD' gives me the same error)

 

Update-IntuneManagedDevice : 400 Bad Request
{
"error": {
"code": "InternalError",
"message": "{\r\n \"_version\": 3,\r\n \"Message\": \"An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: 6f743002-b0e0-48ed-a25d-0cdd33870efd - Url:
https://fef.msub02.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDe... \"CustomApiErrorPhrase\":
\"\",\r\n \"RetryAfter\": null,\r\n \"ErrorSourceService\": \"\",\r\n \"HttpHeaders\": \"{}\"\r\n}",
"innerError": {
"request-id": "6f743002-b0e0-48ed-a25d-0cdd33870efd",
"date": "2019-03-06T14:08:02"
}
}
}
At line:1 char:92
+ ... ddeviceid | Update-IntuneManagedDevice -deviceCategoryDisplayName 'BY ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ConnectionError: (@{Request=; Response=}:PSObject) [Update-IntuneManagedDevice], HttpRequestException
+ FullyQualifiedErrorId : PowerShellGraphSDK_HttpRequestError,Microsoft.Intune.PowerShellGraphSDK.PowerShellCmdlets.Update_IntuneManagedDevice

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
Extentions Synchronization
ChirmyRam in Discussions on
3 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies