命名空间:microsoft.graph
重要
Microsoft Graph /beta
版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
更新设备的属性。 只能通过批准的移动设备管理 (MDM) 应用更新设备的某些属性。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
Directory.AccessAsUser.All |
不可用。 |
委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
应用程序 |
Device.ReadWrite.All |
Directory.ReadWrite.All |
在仅限应用程序的情况下,对于非 Windows 设备,即 ,如果 operatingSystem 属性不是 Windows
,则应用只能更新 extensionAttributes 属性。
重要
在具有工作或学校帐户的委托方案中,必须为登录用户分配受支持的Microsoft Entra角色或具有支持的角色权限的自定义角色。
Intune管理员是此操作支持的最低特权角色。 具有云设备管理员角色的调用用户只能启用或禁用设备,具有Windows 365管理员角色的用户只能更新基本设备属性。
HTTP 请求
可以使用设备的 ID 或 deviceId 对设备进行寻址。
PATCH /devices/{id}
PATCH /devices(deviceId='{deviceId}')
名称 |
说明 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
请求正文
在请求正文中,提供应更新的 device 属性值。 请求正文中不包括的现有属性将保留其以前的值,或根据对其他属性值的更改重新计算。 为了实现最佳性能,不得添加未变化的现有值。
属性 |
类型 |
说明 |
accountEnabled |
Boolean |
启用帐户时为 true ,否则为 false 。 只有至少具有 云设备管理员 角色的调用方才能更新此属性。 |
alternativeNames |
字符串集合 |
设备的可选名称列表,例如 resourceIds 。 |
displayName |
String |
设备显示名称。 |
isCompliant |
布尔值 |
true 如果设备符合移动设备管理 (MDM) 策略,则为 ;否则为 false 。 这只能通过任何设备 OS 类型的Intune或 Windows OS 设备的已批准的 MDM 应用进行更新。 |
isManaged |
布尔值 |
true 如果设备由移动设备管理 (MDM) 应用管理,则为 ;否则为 false 。 这只能通过任何设备 OS 类型的Intune或 Windows OS 设备的已批准的 MDM 应用进行更新。 |
operatingSystem |
String |
设备上的操作系统类型。 |
operatingSystemVersion |
String |
设备上操作系统的版本。 |
由于 设备 资源支持 扩展,因此可以使用 PATCH
操作在现有 设备 实例中扩展的自定义属性中添加、更新或删除自己的特定于应用的数据。
响应
如果成功,此方法返回 204 No Content
响应代码。
示例
示例 1:更新设备的 accountEnabled 属性
请求
PATCH https://graph.microsoft.com/beta/devices/7c06cd31-7c30-4f3b-a5c3-444cd8dd63ac
Content-type: application/json
{
"accountEnabled": false
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Device
{
AccountEnabled = false,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Devices["{device-id}"].PatchAsync(requestBody);
mgc-beta devices patch --device-id {device-id} --body '{\
"accountEnabled": false\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewDevice()
accountEnabled := false
requestBody.SetAccountEnabled(&accountEnabled)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
devices, err := graphClient.Devices().ByDeviceId("device-id").Patch(context.Background(), requestBody, nil)
// 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);
Device result = graphClient.devices().byDeviceId("{device-id}").patch(device);
const options = {
authProvider,
};
const client = Client.init(options);
const device = {
accountEnabled: false
};
await client.api('/devices/7c06cd31-7c30-4f3b-a5c3-444cd8dd63ac')
.version('beta')
.update(device);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Device;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Device();
$requestBody->setAccountEnabled(false);
$result = $graphServiceClient->devices()->byDeviceId('device-id')->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.DirectoryManagement
$params = @{
accountEnabled = $false
}
Update-MgBetaDevice -DeviceId $deviceId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.device import Device
# 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,
)
result = await graph_client.devices.by_device_id('device-id').patch(request_body)
响应
HTTP/1.1 204 No Content
示例 2:在设备上写入 extensionAttributes
请求
PATCH https://graph.microsoft.com/beta/devices/7c06cd31-7c30-4f3b-a5c3-444cd8dd63ac
Content-type: application/json
{
"extensionAttributes": {
"extensionAttribute1": "BYOD-Device"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Device
{
ExtensionAttributes = new OnPremisesExtensionAttributes
{
ExtensionAttribute1 = "BYOD-Device",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Devices["{device-id}"].PatchAsync(requestBody);
mgc-beta devices patch --device-id {device-id} --body '{\
"extensionAttributes": {\
"extensionAttribute1": "BYOD-Device"\
}\
}\
'
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewDevice()
extensionAttributes := graphmodels.NewOnPremisesExtensionAttributes()
extensionAttribute1 := "BYOD-Device"
extensionAttributes.SetExtensionAttribute1(&extensionAttribute1)
requestBody.SetExtensionAttributes(extensionAttributes)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
devices, err := graphClient.Devices().ByDeviceId("device-id").Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Device device = new Device();
OnPremisesExtensionAttributes extensionAttributes = new OnPremisesExtensionAttributes();
extensionAttributes.setExtensionAttribute1("BYOD-Device");
device.setExtensionAttributes(extensionAttributes);
Device result = graphClient.devices().byDeviceId("{device-id}").patch(device);
const options = {
authProvider,
};
const client = Client.init(options);
const device = {
extensionAttributes: {
extensionAttribute1: 'BYOD-Device'
}
};
await client.api('/devices/7c06cd31-7c30-4f3b-a5c3-444cd8dd63ac')
.version('beta')
.update(device);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Device;
use Microsoft\Graph\Beta\Generated\Models\OnPremisesExtensionAttributes;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Device();
$extensionAttributes = new OnPremisesExtensionAttributes();
$extensionAttributes->setExtensionAttribute1('BYOD-Device');
$requestBody->setExtensionAttributes($extensionAttributes);
$result = $graphServiceClient->devices()->byDeviceId('device-id')->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.DirectoryManagement
$params = @{
extensionAttributes = @{
extensionAttribute1 = "BYOD-Device"
}
}
Update-MgBetaDevice -DeviceId $deviceId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.device import Device
from msgraph_beta.generated.models.on_premises_extension_attributes import OnPremisesExtensionAttributes
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Device(
extension_attributes = OnPremisesExtensionAttributes(
extension_attribute1 = "BYOD-Device",
),
)
result = await graph_client.devices.by_device_id('device-id').patch(request_body)
响应
HTTP/1.1 204 No Content
相关内容