Closed lcsfreire closed 4 years ago
Hi @lcsfreire
If you complete the same operation in the UI does it work? What kind of Win10 device is it? AADJ, Hybrid?
I've just tested using the script to set an Azure AD Joined Window 10 device and it worked as expected.
Thanks
Dave
Hello @davefalkus at UI it works without issue but we would like to automate the task. The W10 is AADJ device.
Using MicrosoftGraph explorer when we test $Resource = "deviceManagement/managedDevices('$IntuneDeviceId')/users/`$ref" $uri = "https://graph.microsoft.com/$graphApiVersion/$($Resource)" we don't get any result
if we remove "/users/`$ref" on MicrosoftGraph we get all device attributes: $Resource = "deviceManagement/managedDevices('$IntuneDeviceId')" $uri = "https://graph.microsoft.com/$graphApiVersion/$($Resource)"
@lcsfreire
Can you use the Get script with your DeviceName like the below and share the output?
.\Win10_PrimaryUser_Get.ps1 -DeviceName win10-01
Device name: WIN10-01 Intune device id: e774b98b-9e40-457d-a8b1-d396030b01ab Intune Primary user id: b5293b42-8745-4960-94b7-89f9757e9edc
AAD Registered Owner: Id: b5293b42-8745-4960-94b7-89f9757e9edc Name: Peter
RegisteredUsers: Id: b5293b42-8745-4960-94b7-89f9757e9edc Name: Peter
The script uses the same graph calls as the UI. If you want to query the primary user the graph call is:
Hello @davefalkus , i have run the script .\Win10_PrimaryUser_Get.ps1 DESKTOP-XXXXXX and i don't have any issue. The result of the script:
Checking for AzureAD module... AzureAD PowerShell module not found, looking for AzureADPreview
Device name: DESKTOP-XXXXXX Intune device id: fc6385b3-2b98-XXXXXXXXX Intune Primary user id: dda3733e-a290-401a-XXXXXXXXX
AAD Registered Owner: Id: dda3733e-a290-401a-XXXXXXXXXX Name: XXXXX
RegisteredUsers: Id: dda3733e-a290-401a-XXXXXXXX Name: XXXX
However we can't make work the set script.
Many thanks for your help
Thanks @lcsfreire
Few more things to confirm, the account that your using to run the script is the same as the account you use to change in the UI?
Also from our blog post: https://techcommunity.microsoft.com/t5/intune-customer-success/change-the-intune-primary-user-public-preview-now-available/ba-p/1221264
I can't get the set script to fail, does the set script work against any device or is it just happening for one?
Thanks
Dave
Hello, running the sample script Win10_PrimaryUser_Set.ps1 we the following error: Can you please help?
Response content: { "error": { "code": "BadRequest", "message": "{\r\n \"_version\": 3,\r\n \"Message\": \"An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity I D: 3213d377-e496-4ebb-xxxxxxxxx-7 - Url: https://fef.msub01.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices%28%27fc6385b3-2b9 8-47fc-b8e2-xxxxxxxxxxx%27%29/users/%24ref?api-version=5020-02-21\",\r\n \"CustomApiErrorPhrase\": \"\",\r\n \"RetryAfter\": null,\r\n \"ErrorSourceService\": \"\",\r \n \"HttpHeaders\": \"{}\"\r\n}", "innerError": { "request-id": "3213d377-e496--xxxxxxxxx57", "date": "2020-04-06T11:37:08" } } }
Set-IntuneDevicePrimaryUser : Request to https://graph.microsoft.com/beta/deviceManagement/managedDevices('-b8e2-0f966d6cbc8e')/users/$ref failed with HTTP Status BadRequest Bad Request Au caractère C:\Users\PC\Desktop\intune_set_primary_user.ps1:498 : 43
Set-IntuneDevicePrimaryUser error Au caractère C:\Users\PC\Desktop\intune_set_primary_user.ps1:405 : 3
Many thanks Best Regards