Adding serialnumbers using New-MgDeviceManagementImportedDeviceIdentity - error

Mikael Östergren 1 Reputation point
2022-05-03T06:46:12.723+00:00

I am trying to use the cmd New-MgDeviceManagementImportedDeviceIdentity to insert new serialnumbers from our assetDB.
connect-mggraph works fine, using certificate and appID.

My testing example (serial is fakeserial, but valid):

$NewID = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphImportedDeviceIdentity
$NewID.Description = "A Description"
$NewID.ImportedDeviceIdentifier = "07C200200007"
$NewID.ImportedDeviceIdentityType = "serialNumber"

I then run the command
New-MgDeviceManagementImportedDeviceIdentity -BodyParameter $NewID

The error i receive looks like this.
New-MgDeviceManagementImportedDeviceIdentity : No OData route exists that match template ~/singleton/navigation with http verb POST for request /DeviceEnrollmentFE_2204/StatelessDeviceEnrollmentFESe
rvice/deviceManagement/importedDeviceIdentities.

I posted a ticket about this here: 147
I then tried the suggestion using :

 $ImportedDeviceIdentities = @{
    "@odata.type" = "#microsoft.graph.importedDeviceIdentity"
    Description = "A Description"
    ImportedDeviceIdentifier = "07C200200007"
    ImportedDeviceIdentityType = "serialNumber"
    \# Add more details.
  } 

   Import-MgDeviceManagementImportedDeviceIdentityList -ImportedDeviceIdentities $ImportedDeviceIdentities -OverwriteImportedDeviceIdentities:$false

But this generated a new error:
Import-MgDeviceManagementImportedDeviceIdentityList : Unable to cast object of type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonObject' to type 'Microsoft.Graph.PowerShell.Runtime.Json.JsonArray'.
At line:11 char:1

  • Import-MgDeviceManagementImportedDeviceIdentityList -ImportedDeviceId ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [Import-MgDevice..._ImportExpanded], InvalidCastException
  • FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.ImportMgDeviceManagementImportedDeviceIdentityList_ImportExpanded
Microsoft Intune Enrollment
Microsoft Intune Enrollment
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Enrollment: The process of requesting, receiving, and installing a certificate.
1,254 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Crystal-MSFT 43,381 Reputation points Microsoft Vendor
    2022-05-04T02:27:00.613+00:00

    @Mikael Östergren , From your description, we are using "New-MgDeviceManagementImportedDeviceIdentity" to import device identities. But it is failed.

    Maybe you can try the similar command as below to see if it works:

    Install-Module Microsoft.Graph.DeviceManagement.Enrolment   
    Import-Module Microsoft.Graph.DeviceManagement.Enrolment  
    Connect-MgGraph    
    New-MgDeviceManagementImportedWindowAutopilotDeviceIdentity -serialnumber "xxxxxxxx"  
    

    Hope it can help.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.