Dans les scénarios délégués avec des comptes professionnels ou scolaires, l’utilisateur connecté doit se voir attribuer un rôle Microsoft Entra pris en charge ou un rôle personnalisé avec une autorisation de rôle prise en charge. Les rôles les moins privilégiés suivants sont pris en charge pour cette opération.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new Device
{
AccountEnabled = false,
AlternativeSecurityIds = new List<AlternativeSecurityId>
{
new AlternativeSecurityId
{
Type = 2,
Key = Convert.FromBase64String("base64Y3YxN2E1MWFlYw=="),
},
},
DeviceId = "4c299165-6e8f-4b45-a5ba-c5d250a707ff",
DisplayName = "Test device",
OperatingSystem = "linux",
OperatingSystemVersion = "1",
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Devices.PostAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Device device = new Device();
device.setAccountEnabled(false);
LinkedList<AlternativeSecurityId> alternativeSecurityIds = new LinkedList<AlternativeSecurityId>();
AlternativeSecurityId alternativeSecurityId = new AlternativeSecurityId();
alternativeSecurityId.setType(2);
byte[] key = Base64.getDecoder().decode("base64Y3YxN2E1MWFlYw==");
alternativeSecurityId.setKey(key);
alternativeSecurityIds.add(alternativeSecurityId);
device.setAlternativeSecurityIds(alternativeSecurityIds);
device.setDeviceId("4c299165-6e8f-4b45-a5ba-c5d250a707ff");
device.setDisplayName("Test device");
device.setOperatingSystem("linux");
device.setOperatingSystemVersion("1");
Device result = graphClient.devices().post(device);
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.device import Device
from msgraph.generated.models.alternative_security_id import AlternativeSecurityId
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Device(
account_enabled = False,
alternative_security_ids = [
AlternativeSecurityId(
type = 2,
key = base64.urlsafe_b64decode("base64Y3YxN2E1MWFlYw=="),
),
],
device_id = "4c299165-6e8f-4b45-a5ba-c5d250a707ff",
display_name = "Test device",
operating_system = "linux",
operating_system_version = "1",
)
result = await graph_client.devices.post(request_body)