// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.DeviceManagement.DeviceConfigurations.Item.Assign;
using Microsoft.Graph.Models;
var requestBody = new AssignPostRequestBody
{
Assignments = new List<DeviceConfigurationAssignment>
{
new DeviceConfigurationAssignment
{
OdataType = "#microsoft.graph.deviceConfigurationAssignment",
Id = "d59b6342-6342-d59b-4263-9bd542639bd5",
Target = new ConfigurationManagerCollectionAssignmentTarget
{
OdataType = "microsoft.graph.configurationManagerCollectionAssignmentTarget",
CollectionId = "Collection Id value",
},
},
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.DeviceManagement.DeviceConfigurations["{deviceConfiguration-id}"].Assign.PostAsAssignPostResponseAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphdevicemanagement "github.com/microsoftgraph/msgraph-sdk-go/devicemanagement"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphdevicemanagement.NewAssignPostRequestBody()
deviceConfigurationAssignment := graphmodels.NewDeviceConfigurationAssignment()
id := "d59b6342-6342-d59b-4263-9bd542639bd5"
deviceConfigurationAssignment.SetId(&id)
target := graphmodels.NewConfigurationManagerCollectionAssignmentTarget()
collectionId := "Collection Id value"
target.SetCollectionId(&collectionId)
deviceConfigurationAssignment.SetTarget(target)
assignments := []graphmodels.DeviceConfigurationAssignmentable {
deviceConfigurationAssignment,
}
requestBody.SetAssignments(assignments)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
assign, err := graphClient.DeviceManagement().DeviceConfigurations().ByDeviceConfigurationId("deviceConfiguration-id").Assign().PostAsAssignPostResponse(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.devicemanagement.deviceconfigurations.item.assign.AssignPostRequestBody assignPostRequestBody = new com.microsoft.graph.devicemanagement.deviceconfigurations.item.assign.AssignPostRequestBody();
LinkedList<DeviceConfigurationAssignment> assignments = new LinkedList<DeviceConfigurationAssignment>();
DeviceConfigurationAssignment deviceConfigurationAssignment = new DeviceConfigurationAssignment();
deviceConfigurationAssignment.setOdataType("#microsoft.graph.deviceConfigurationAssignment");
deviceConfigurationAssignment.setId("d59b6342-6342-d59b-4263-9bd542639bd5");
ConfigurationManagerCollectionAssignmentTarget target = new ConfigurationManagerCollectionAssignmentTarget();
target.setOdataType("microsoft.graph.configurationManagerCollectionAssignmentTarget");
target.setCollectionId("Collection Id value");
deviceConfigurationAssignment.setTarget(target);
assignments.add(deviceConfigurationAssignment);
assignPostRequestBody.setAssignments(assignments);
var result = graphClient.deviceManagement().deviceConfigurations().byDeviceConfigurationId("{deviceConfiguration-id}").assign().post(assignPostRequestBody);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\DeviceManagement\DeviceConfigurations\Item\Assign\AssignPostRequestBody;
use Microsoft\Graph\Generated\Models\DeviceConfigurationAssignment;
use Microsoft\Graph\Generated\Models\ConfigurationManagerCollectionAssignmentTarget;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new AssignPostRequestBody();
$assignmentsDeviceConfigurationAssignment1 = new DeviceConfigurationAssignment();
$assignmentsDeviceConfigurationAssignment1->setOdataType('#microsoft.graph.deviceConfigurationAssignment');
$assignmentsDeviceConfigurationAssignment1->setId('d59b6342-6342-d59b-4263-9bd542639bd5');
$assignmentsDeviceConfigurationAssignment1Target = new ConfigurationManagerCollectionAssignmentTarget();
$assignmentsDeviceConfigurationAssignment1Target->setOdataType('microsoft.graph.configurationManagerCollectionAssignmentTarget');
$assignmentsDeviceConfigurationAssignment1Target->setCollectionId('Collection Id value');
$assignmentsDeviceConfigurationAssignment1->setTarget($assignmentsDeviceConfigurationAssignment1Target);
$assignmentsArray []= $assignmentsDeviceConfigurationAssignment1;
$requestBody->setAssignments($assignmentsArray);
$result = $graphServiceClient->deviceManagement()->deviceConfigurations()->byDeviceConfigurationId('deviceConfiguration-id')->assign()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.devicemanagement.deviceconfigurations.item.assign.assign_post_request_body import AssignPostRequestBody
from msgraph.generated.models.device_configuration_assignment import DeviceConfigurationAssignment
from msgraph.generated.models.configuration_manager_collection_assignment_target import ConfigurationManagerCollectionAssignmentTarget
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = AssignPostRequestBody(
assignments = [
DeviceConfigurationAssignment(
odata_type = "#microsoft.graph.deviceConfigurationAssignment",
id = "d59b6342-6342-d59b-4263-9bd542639bd5",
target = ConfigurationManagerCollectionAssignmentTarget(
odata_type = "microsoft.graph.configurationManagerCollectionAssignmentTarget",
collection_id = "Collection Id value",
),
),
],
)
result = await graph_client.device_management.device_configurations.by_device_configuration_id('deviceConfiguration-id').assign.post(request_body)