Hi there,
If you have the device Names and their Azure AD Device IDs, the below script will help you in adding Azure AD joined devices to an AAD group.
$groupName = "myAADGroupName"
try {
$deviceList = Import-Csv -Path "D:\DevicesToAdd.csv"
Connect-AzureAD
$groupObj = Get-AzureADGroup -SearchString $groupName
foreach ($device in $deviceList) {
$deviceObj = Get-AzureADDevice -SearchString $device.DeviceName
if($deviceObj -ne $null){
try{
foreach($dev in $deviceObj){
if($dev.DeviceId -eq $device.azureADDeviceId){
Add-AzureADGroupMember -ObjectId $groupObj.ObjectId -RefObjectId $dev.ObjectId
}
}
}
catch{}
}
else{
Write-Host "No device found:$($device.DeviceName)"
}
}
}
catch {
Write-Host -Message $_
}
Hope this resolves your Query !!
------------------------------------------------------------------------------------------------------------------------------------------------------------
--If the reply is helpful, please Upvote and Accept it as an answer–