Azure | Intune: Powershell to generate Object IDs for Bulk operations in Device group

Published on: August 23, 2021 | Reading Time: 3 min | Last Modified : August 23, 2021

Azure | Intune: Powershell to generate template to be used in Bulk operations in Device group

Background

As an Intune Admin, We know how to create device group in Azure AD or Intune. We know how to add and remove devices from device group. This manual step is helpful only when you need to add or remove few devices. But what would you do when you need to remove 50-100 devices. Now, this is where you don’t want to go manual way. Here, use of Bulk operation under device group will be helpful.

Limitation

When you will try to do so, you get to import the CSV (template) containing list in some format available to preview and download. In short, now your csv should contain device object. This would have been more easier if Microsoft would have given option to add device names directly instead of device object and to pull out device object for all device names and to feed this in CSV file.

Solution

In this post we will prepare a PowerShell Script that will intake device names as a CSV list and it will generate the CSV of collection of device object IDs in required template format.

Steps to bulk import group members

  1. Sign in to the Azure or MEM portal.
  2. Select Groups > All groups. Search for required group.
  3. Open the group to which you need to add members.
  4. Select Import members under Bulk operations. import1.jpg
  5. Now, create your own CSV file that would contain device names as shown below:- excel1.jpg
  6. Run the below powershell script to fetch Object IDs of provided device names given in step 5.
Install-module -name msonline -force 
Connect-MsolService
$CHGList = Import-Csv -path "C:\temp\MachineNames.csv"
$ObjectID = @(
    @{ Name = 'version:v1.0'; Expression = { $_.'ObjectId' } }
)
'*'| Select-Object -Property $ObjectID |Export-CSV -Path "C:\temp\testx.csv" -NoTypeInformation -Append -Force
ForEach ($displayName in $CHGList) {
    Get-MsolDevice -Name $displayName.displayName | Select-Object -Property $ObjectID |Export-CSV -Path "C:\temp\BulkUploadtemplate.csv" -NoTypeInformation -Append
}

MachineNames.csv –> Create a device list, column name should be displayName and mention all required devices names under this. And place this csv in C:\temp location. testx.csv –> Creates template (Done by script), you can ignore this. BulkUploadtemplate.csv –> Creates required template (Done by script)

–> On the Bulk import group members page, Upload BulkUploadtemplate.csv file.

import2.jpg

–> Select Submit to start the Azure bulk operation that imports the group members to the group.

–> After sometime, you will see a notification saying the bulk operation succeeded.

Troubleshooting Reference

If BulkUploadtemplate.csv is not working then please download the template and copy object IDs from this CSV and try to import it.

Check import status

You can see the status of all of your pending bulk requests in the Bulk operation results page.

BulkOpnResult.jpg

Note: Each bulk activity to import a list of group members can run for max one hour.

Similarly, you can use this script for removing bulk members from Device group.

References