Add Groups to Intunes DeviceShell Script with powershell graph api not works - What is the correct commando?

Andreas Mühlemann 1 Reputation point
2022-05-16T11:18:45.883+00:00

Hello there
I have a problem with an Powershell Command from Module MicrosoftGraph.
Maybe is there anyone the can tell my what the correct command are.

The command

Set-MgDeviceManagementDeviceConfiguration -DeviceConfigurationId $deviceConfigurationId -BodyParameter $params  

With this body

$params = @{  
    Assignments = @(  
        @{  
            Target = @{  
                "@odata.type" = "#microsoft.graph.groupAssignmentTarget"  
                GroupId = <"GroupID">  
            }  
        }  
    )  
}  

It's working but remove all another assigned groups.

So I think the correct command will be the following:

Update-MgDeviceManagementDeviceShellScript -DeviceShellScriptId $deviceShellScriptId -BodyParameter $params  

But what is the correct Body and how do assign with more groups of times?

I have also tried with the following command:

Update-MgDeviceManagementDeviceShellScript -DeviceShellScriptId "0cee72b4-6af0-4d25-96c1-ece01bd885f3" -GroupAssignments [TargetGroupId <GroupId>]  

But I get a mistake back:

Update-MgDeviceManagementDeviceShellScript: Cannot process argument transformation on parameter 'GroupAssignments'. Cannot convert value "[TargetGroupId" to type "Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDeviceManagementScriptGroupAssignment[]". Error: "Cannot convert the "[TargetGroupId" value of type "System.String" to type “Microsoft.Graph.PowerShell.Models.IMicrosoftGraphDeviceManagementScriptGroupAssignment"."  

Here link to Microsoft about this:
https://learn.microsoft.com/en-us/graph/api/intune-devices-deviceshellscript-update?view=graph-rest-beta.

I would be very happy if anyone could help me with my problem.

Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
4,301 questions
{count} votes