デバイスを一覧表示する
[アーティクル]
04/06/2022
3 人の共同作成者
この記事の内容
名前空間: microsoft.graph
組織に登録されているデバイス オブジェクトの一覧を取得します。
アクセス許可
この 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
ベアラー {token}。必須。
ConsistencyLevel
最終的。 このヘッダーと $count は、$search を使用する場合、または $filter の特別な使用をする場合に必要です。 ConsistencyLevel および $count の使用方法の詳細については、「Azure AD ディレクトリ オブジェクトの詳細クエリ機能 」を参照してください。
要求本文
このメソッドには、要求本文を指定しません。
応答
成功した場合、このメソッドは 200 OK 応答コードと、応答本文で device オブジェクトのコレクションを返します。
例
例 1: デバイスのリストを取得する
要求
要求の例を次に示します。
GET https://graph.microsoft.com/v1.0/devices
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 のドキュメントを参照してください 。
応答
応答の例を次に示します。
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。
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: デバイスの数のみを取得する
要求
要求の例を次に示します。 この要求では、$count が要求にあるため、ConsistencyLevel ヘッダーを eventual に設定する必要があります。 ConsistencyLevel および $count の使用方法の詳細については、「Azure AD ディレクトリ オブジェクトの詳細クエリ機能 」を参照してください。
注: $countおよび$searchのクエリパラメーターは、現在 Azure ADB2C テナントでは使用できません。
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' で始まる表示名を持つ 1 つのデバイスを取得する
要求
要求の例を次に示します。 この要求では、$orderBy と $filter の両方のクエリ パラメーターがあるため、ConsistencyLevel ヘッダーを eventual および $count=true クエリ文字列に設定することが必要です。 ConsistencyLevel および $count の使用方法の詳細については、「Azure AD ディレクトリ オブジェクトの詳細クエリ機能 」を参照してください。
注: $countおよび$searchのクエリパラメーターは、現在 Azure ADB2C テナントでは使用できません。
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" という文字を含む表示名を持つデバイスを取得します。
要求
要求の例を次に示します。 この要求では、$search と $count=true のクエリ文字列が要求内にあるため、ConsistencyLevel ヘッダーを eventual に設定する必要があります。 ConsistencyLevel および $count の使用方法の詳細については、「Azure AD ディレクトリ オブジェクトの詳細クエリ機能 」を参照してください。
注: $countおよび$searchのクエリパラメーターは、現在 Azure ADB2C テナントでは使用できません。
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 のドキュメントを参照してください 。
応答
応答の例を次に示します。
注: ここに示す応答オブジェクトは、読みやすさのために短縮されている場合があります。
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 でフィルターを使用してデバイスを取得する
要求
要求の例を次に示します。 extensionAttributes $filter プロパティは高度なクエリ パラメーターでのみサポートされているので、この要求には 、ConsistencyLevel eventual $count=true ヘッダーセットとクエリ文字列が必要です。 ConsistencyLevel および $count の使用方法の詳細については、「Azure AD ディレクトリ オブジェクトの詳細クエリ機能 」を参照してください。
注: $countおよび$searchのクエリパラメーターは、現在 Azure ADB2C テナントでは使用できません。
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"
}
]
}
]
}