I have a powershell function that calss a C# function app to enroll a device in Autopilot. I can't get it to work. I quite sure the problem lies with the hardware identifier binary blob. I tried every string format but I always get the same error
Here's how the hardware identifier is retreived in powershell
$devDetail = (Get-CimInstance -CimSession $session -Namespace root/cimv2/mdm/dmmap -Class MDM_DevDetail_Ext01 -Filter "InstanceID='Ext' AND ParentID='./DevDetail'")
if ($devDetail -and (-not $Force))
{
$hash = $devDetail.DeviceHardwareData
}
then the hash is sent in the body of a HTTP call along with some other info
Here's the relevant part of the C# function
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
string HI = data?.hardwareIdentifier;
var NouvelEquipement = new ImportedWindowsAutopilotDeviceIdentity {
GroupTag = req.Query["GroupTag"],
HardwareIdentifier = System.Text.Encoding.Unicode.GetBytes(HI),
SerialNumber = req.Query["SerialNumber"],
State = new ImportedWindowsAutopilotDeviceIdentityState {
DeviceImportStatus = ImportedWindowsAutopilotDeviceIdentityImportStatus.Pending,
DeviceErrorCode = 0,
}
};
var retour = await graphClient.DeviceManagement.ImportedWindowsAutopilotDeviceIdentities
.Request()
.AddAsync(NouvelEquipement);
I get the following error
2022-12-23T18:07:27.944 [Error] Executed 'AjoutEquipement' (Failed, Id=xxxxxxx, Duration=4062ms)Code: InternalErrorMessage: {"_version": 3,"Message": "An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: xxxxxxxxxx - Url: https://fef.msua04.manage.microsoft.com/DeviceEnrollmentFE_2212/StatelessDeviceEnrollmentFEService/deviceManagement/importedWindowsAutopilotDeviceIdentities/microsoft.management.services.api.import?api-version=2021-01-22","CustomApiErrorPhrase": "","RetryAfter": null,"ErrorSourceService": "","HttpHeaders": "{}"}Inner error:AdditionalData:date: 2022-12-23T18:07:27request-id: xxxxxxxclient-request-id: xxxxxxxxxxxClientRequestId: xxxxxxxxxxx