列出设备
本文内容
命名空间:microsoft.graph
检索组织中注册的 device 对象的列表。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
Device.Read.All、Directory.ReadWrite.All
委派(个人 Microsoft 帐户)
不支持。
应用程序
Device.Read.All、Device.ReadWrite.All、Directory.Read.All、Directory.ReadWrite.All
HTTP 请求
GET /devices
可选的查询参数
此方法支持使用 $count、$expand、$filter、$orderBy、$search、$select 和 $top OData 查询参数 以帮助自定义响应。 只有将 ConsistencyLevel 标头设置为 eventual 和 $count 时,才支持某些查询。 有关详细信息,请参阅 Azure AD 目录对象的高级查询功能 。
名称
说明
Authorization
Bearer {token}。必需。
ConsistencyLevel
最终。 当使用 $search 或 $filter 的特定用法时,需要此标头和 $count。 有关使用 ConsistencyLevel 和 $count 的详细信息,请参阅 Azure AD 目录对象的高级查询功能 。
请求正文
请勿提供此方法的请求正文。
响应
如果成功,此方法在响应正文中返回 200 OK 响应代码和 device 对象集合。
示例
示例 1:获取设备列表
请求
下面展示了示例请求。
GET https://graph.microsoft.com/v1.0/devices
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var devices = await graphClient.Devices
.Request()
.GetAsync();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
let devices = await client.api('/devices')
.get();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/devices"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphDevice *device = [[MSGraphDevice alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
DeviceCollectionPage devices = graphClient.devices()
.buildRequest()
.get();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
result, err := graphClient.Devices().Get()
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"accountEnabled":true,
"deviceId":"00000000-0000-0000-0000-000000000000",
"deviceVersion":1,
"displayName":"contoso_Android",
"Manufacturer":"Google",
"Model":"Pixel 3a",
"operatingSystemVersion":"10.0"
}
]
}
示例 2:仅获取设备计数
请求
下面展示了示例请求。 此请求要求将 ConsistencyLevel 标头设置为 eventual,因为在请求中有 $count。 有关使用 ConsistencyLevel 和 $count 的详细信息,请参阅 Azure AD 目录对象的高级查询功能 。
注意: $count和$search 查询参数当前在 Azure AD B2C 租户中不可用。
GET https://graph.microsoft.com/v1.0/devices/$count
ConsistencyLevel: eventual
响应
下面展示了示例响应。
HTTP/1.1 200 OK
Content-type: text/plain
294
示例 3:列出所有设备并仅返回其 id 和 extensionAttributes 属性
请求
GET https://graph.microsoft.com/beta/devices?$select=id,extensionAttributes
响应
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#devices(id,extensionAttributes)",
"value": [
{
"id": "6a59ea83-02bd-468f-a40b-f2c3d1821983",
"extensionAttributes": {
"extensionAttribute1": null,
"extensionAttribute2": null,
"extensionAttribute3": null,
"extensionAttribute4": null,
"extensionAttribute5": null,
"extensionAttribute6": null,
"extensionAttribute7": null,
"extensionAttribute8": null,
"extensionAttribute9": null,
"extensionAttribute10": null,
"extensionAttribute11": null,
"extensionAttribute12": null,
"extensionAttribute13": null,
"extensionAttribute14": null,
"extensionAttribute15": null
}
}
]
}
示例 4:使用 $filter 和 $top 获取一个设备,显示名称以"a"开头(包括返回的对象计数)
请求
下面展示了示例请求。 此请求需要将 ConsistencyLevel 标头设置为 eventual 和 $count=true 查询字符串,因为请求同时具有 $orderBy 和 $filter 查询参数。 有关使用 ConsistencyLevel 和 $count 的详细信息,请参阅 Azure AD 目录对象的高级查询功能 。
注意: $count和$search 查询参数当前在 Azure AD B2C 租户中不可用。
GET https://graph.microsoft.com/v1.0/devices?$filter=startswith(displayName, 'a')&$count=true&$top=1&$orderby=displayName
ConsistencyLevel: eventual
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true")
};
var contacts = await graphClient.Contacts
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Filter("startswith(displayName,'A')")
.OrderBy("displayName")
.Top(1)
.GetAsync();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
let devices = await client.api('/devices')
.header('ConsistencyLevel','eventual')
.filter('startswith(displayName, \'a\')')
.orderby('displayName')
.top(1)
.get();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/devices?$filter=startswith(displayName,%20'a')&$count=true&$top=1&$orderby=displayName"]]];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setValue:@"eventual" forHTTPHeaderField:@"ConsistencyLevel"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphDevice *device = [[MSGraphDevice alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
DeviceCollectionPage devices = graphClient.devices()
.buildRequest( requestOptions )
.filter("startswith(displayName, 'a')")
.orderBy("displayName")
.top(1)
.get();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.ContactsRequestBuilderGetQueryParameters{
Filter: "startswith(displayName,'A')",
Count: true,
Top: 1,
Orderby: "displayName",
}
headers := map[string]string{
"ConsistencyLevel": "eventual"
}
options := &msgraphsdk.ContactsRequestBuilderGetOptions{
Q: requestParameters,
H: headers,
}
result, err := graphClient.Contacts().Get(options)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Identity.DirectoryManagement
Get-MgContact -Filter "startswith(displayName,'A')" -CountVariable CountVar -Top 1 -Sort "displayName" -ConsistencyLevel eventual
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#devices",
"@odata.count":1,
"value":[
{
"accountEnabled":true,
"deviceId":"00000000-0000-0000-0000-000000000000",
"deviceVersion":1,
"displayName":"a_device_1",
"Manufacturer":"Google",
"Model":"Pixel 3a",
"operatingSystemVersion":"10.0"
}
]
}
示例 5:$search获取显示名称包含字母"Android"的设备,包括返回的对象计数
请求
下面展示了示例请求。 此请求要求将 ConsistencyLevel 标头设置为 eventual,因为在请求中有 $search 和 $count=true 查询字符串。 有关使用 ConsistencyLevel 和 $count 的详细信息,请参阅 Azure AD 目录对象的高级查询功能 。
注意: $count和$search 查询参数当前在 Azure AD B2C 租户中不可用。
GET https://graph.microsoft.com/v1.0/devices?$search="displayName:Android"&$count=true
ConsistencyLevel: eventual
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true")
};
var devices = await graphClient.Devices
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Search("displayName:Android")
.GetAsync();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
let devices = await client.api('/devices')
.header('ConsistencyLevel','eventual')
.search('displayName:Android')
.get();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/devices?$search=%22displayName:Android%22&$count=true"]]];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setValue:@"eventual" forHTTPHeaderField:@"ConsistencyLevel"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphDevice *device = [[MSGraphDevice alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
requestOptions.add(new QueryOption("$search", "displayName:Android"));
DeviceCollectionPage devices = graphClient.devices()
.buildRequest( requestOptions )
.get();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.DevicesRequestBuilderGetQueryParameters{
Search: "%22displayName:Android%22",
Count: true,
}
headers := map[string]string{
"ConsistencyLevel": "eventual"
}
options := &msgraphsdk.DevicesRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
Headers: headers,
}
result, err := graphClient.Devices().GetWithRequestConfigurationAndResponseHandler(options, nil)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Identity.DirectoryManagement
Get-MgDevice -Search "displayName:Android" -CountVariable CountVar -ConsistencyLevel eventual
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#devices",
"@odata.count":1396,
"value":[
{
"accountEnabled":true,
"deviceId":"00000000-0000-0000-0000-000000000000",
"deviceVersion":1,
"displayName":"contoso_Android",
"Manufacturer":"Google",
"Model":"Pixel 3a",
"operatingSystemVersion":"10.0"
}
]
}
示例 6:使用 extensionAttributes 上的筛选器获取设备
请求
下面展示了示例请求。 此请求需要 将 ConsistencyLevel 标头设置为 eventual $count=true 且查询字符串,因为 extensionAttributes $filter 属性仅支持高级查询参数。 有关使用 ConsistencyLevel 和 $count 的详细信息,请参阅 Azure AD 目录对象的高级查询功能 。
注意: $count和$search 查询参数当前在 Azure AD B2C 租户中不可用。
GET https://graph.microsoft.com/v1.0/devices?$filter=extensionAttributes/extensionAttribute1 eq 'BYOD-Device'&$count=true
ConsistencyLevel: eventual
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$count", "true")
};
var devices = await graphClient.Devices
.Request( queryOptions )
.Header("ConsistencyLevel","eventual")
.Filter("extensionAttributes/extensionAttribute1 eq 'BYOD-Device'")
.GetAsync();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
let devices = await client.api('/devices')
.header('ConsistencyLevel','eventual')
.filter('extensionAttributes/extensionAttribute1 eq \'BYOD-Device\'')
.get();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/devices?$filter=extensionAttributes/extensionAttribute1%20eq%20'BYOD-Device'&$count=true"]]];
[urlRequest setHTTPMethod:@"GET"];
[urlRequest setValue:@"eventual" forHTTPHeaderField:@"ConsistencyLevel"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
NSError *jsonError = nil;
MSCollection *collection = [[MSCollection alloc] initWithData:data error:&jsonError];
MSGraphDevice *device = [[MSGraphDevice alloc] initWithDictionary:[[collection value] objectAtIndex: 0] error:&nserror];
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("ConsistencyLevel", "eventual"));
DeviceCollectionPage devices = graphClient.devices()
.buildRequest( requestOptions )
.filter("extensionAttributes/extensionAttribute1 eq 'BYOD-Device'")
.get();
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestParameters := &msgraphsdk.DevicesRequestBuilderGetQueryParameters{
Filter: "extensionAttributes/extensionAttribute1%20eq%20'BYOD-Device'",
Count: true,
}
headers := map[string]string{
"ConsistencyLevel": "eventual"
}
options := &msgraphsdk.DevicesRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
Headers: headers,
}
result, err := graphClient.Devices().GetWithRequestConfigurationAndResponseHandler(options, nil)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
Import-Module Microsoft.Graph.Identity.DirectoryManagement
Get-MgDevice -Filter "extensionAttributes/extensionAttribute1 eq 'BYOD-Device'" -CountVariable CountVar -ConsistencyLevel eventual
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#devices",
"@odata.count": 1,
"value": [
{
"@odata.id": "https://graph.microsoft.com/v2/84841066-274d-4ec0-a5c1-276be684bdd3/directoryObjects/6a59ea83-02bd-468f-a40b-f2c3d1821983/Microsoft.DirectoryServices.Device",
"id": "6a59ea83-02bd-468f-a40b-f2c3d1821983",
"accountEnabled": true,
"approximateLastSignInDateTime": "2021-10-21T06:36:56Z",
"createdDateTime": "2021-09-21T15:16:30Z",
"deviceId": "eab73519-780d-4d43-be6d-a4a89af2a348",
"displayName": "DESKTOP-LK3PESR",
"operatingSystem": "Windows",
"operatingSystemVersion": "10.0.19043.1237",
"physicalIds": [],
"extensionAttributes": {
"extensionAttribute1": "BYOD-Device",
"extensionAttribute2": null,
"extensionAttribute3": null,
"extensionAttribute4": null,
"extensionAttribute5": null,
"extensionAttribute6": null,
"extensionAttribute7": null,
"extensionAttribute8": null,
"extensionAttribute9": null,
"extensionAttribute10": null,
"extensionAttribute11": null,
"extensionAttribute12": null,
"extensionAttribute13": null,
"extensionAttribute14": null,
"extensionAttribute15": null
},
"alternativeSecurityIds": [
{
"type": 2,
"identityProvider": null,
"key": "WAA1ADAAOQA6AD...QBnAD0A"
}
]
}
]
}