Yönetici SDK'sı Dizin Hizmeti
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Admin SDK Directory hizmeti, Apps Script'te Admin SDK'nın Directory API'sini kullanmanıza olanak tanır. Bu API, Google Workspace alanlarının yöneticilerine (bayiler dahil) alanlarındaki cihazları, grupları, kullanıcıları ve diğer öğeleri yönetme olanağı tanır.
Referans
Bu hizmet hakkında ayrıntılı bilgi için Yönetici SDK'sı
Directory API'nin referans dokümanlarına bakın. Apps Komut Dosyası'ndaki tüm gelişmiş hizmetler gibi, Yönetici SDK'sı
Dizin hizmeti de herkese açık API ile aynı nesneleri, yöntemleri ve parametreleri kullanır. Daha fazla bilgi için Yöntem imzaları nasıl belirlenir? başlıklı makaleyi inceleyin.
Sorunları bildirmek ve diğer destek seçeneklerini öğrenmek için Admin SDK Directory destek kılavuzuna bakın.
Örnek kod
Aşağıdaki örnek kodda API'nin 1. sürümü kullanılmaktadır.
Tüm kullanıcıları listeleme
Bu örnekte, bir alandaki tüm kullanıcılar adlarına göre sıralanmış olarak listelenir.
Kullanıcıyı alma
Bu örnek, kullanıcıyı e-posta adresine göre alır ve tüm verilerini JSON dizesi olarak günlüğe kaydeder.
Kullanıcı ekle
Bu örnek, yalnızca gerekli bilgileri içeren yeni bir kullanıcıyı alana ekler. Kullanıcı alanlarının tam listesi için API'nin referans dokümanlarına bakın.
Takma ad oluşturma
Bu örnek, kullanıcı için takma ad oluşturur.
Tüm grupları listele
Bu örnek, alandaki tüm grupları listeler.
Grup üyesi ekleme
Bu örnek, bir kullanıcıyı alandaki mevcut bir gruba ekler.
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-08-31 UTC.
[null,null,["Son güncelleme tarihi: 2025-08-31 UTC."],[[["\u003cp\u003eThe Admin SDK Directory service enables Google Workspace administrators to manage domain resources like users, groups, and devices within Apps Script using the Directory API.\u003c/p\u003e\n"],["\u003cp\u003eThis advanced service requires enabling both the Admin SDK and the specific service before use, and it mirrors the functionality of the public Directory API.\u003c/p\u003e\n"],["\u003cp\u003eSample code snippets demonstrate common tasks like listing and managing users, creating aliases, and handling groups and their members via the Admin SDK Directory service.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the sample code, remember to enable the Admin SDK, replace placeholder values with your specific data, and refer to the documentation for details on API usage and error handling.\u003c/p\u003e\n"]]],[],null,["# Admin SDK Directory Service\n\nThe Admin SDK Directory service allows you to use the Admin SDK's\n[Directory API](/admin-sdk/directory) in Apps Script. This API gives\nadministrators of Google Workspace domains (including\nresellers) the ability to\nmanage devices, groups, users, and other entities in their domains.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced). Additionally, the Admin SDK must be enabled on your domain, as described in the API's [prerequisites documentation](/admin-sdk/directory/v1/guides/prerequisites).\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/admin-sdk/directory/v1/reference) for the Admin SDK\nDirectory API. Like all advanced services in Apps Script, the Admin SDK\nDirectory service uses the same objects, methods, and parameters as the public\nAPI. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Admin SDK Directory support guide](/admin-sdk/directory/support).\n\nSample code\n-----------\n\nThe sample code below uses [version 1](/admin-sdk/directory/v1/reference) of\nthe API.\n\n### List all users\n\nThis sample lists all the users in a domain sorted by first name. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Lists all the users in a domain sorted by first name.\n * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list\n */\nfunction listAllUsers() {\n let pageToken;\n let page;\n do {\n page = AdminDirectory.Users.list({\n domain: 'example.com',\n orderBy: 'givenName',\n maxResults: 100,\n pageToken: pageToken\n });\n const users = page.users;\n if (!users) {\n console.log('No users found.');\n return;\n }\n // Print the user's full name and email.\n for (const user of users) {\n console.log('%s (%s)', user.name.fullName, user.primaryEmail);\n }\n pageToken = page.nextPageToken;\n } while (pageToken);\n}\n```\n\n### Get user\n\nThis sample gets a user by their email address and logs all of their data as a\nJSON string. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Get a user by their email address and logs all of their data as a JSON string.\n * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/get\n */\nfunction getUser() {\n // TODO (developer) - Replace userEmail value with yours\n const userEmail = 'liz@example.com';\n try {\n const user = AdminDirectory.Users.get(userEmail);\n console.log('User data:\\n %s', JSON.stringify(user, null, 2));\n } catch (err) {\n // TODO (developer)- Handle exception from the API\n console.log('Failed with error %s', err.message);\n }\n}\n```\n\n### Add user\n\nThis sample adds a new user to the domain, including only the required\ninformation. For the full list of user fields, see the API's\n[reference documentation](/admin-sdk/directory/v1/reference/users/insert). \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Adds a new user to the domain, including only the required information. For\n * the full list of user fields, see the API's reference documentation:\n * @see https://developers.google.com/admin-sdk/directory/v1/reference/users/insert\n */\nfunction addUser() {\n let user = {\n // TODO (developer) - Replace primaryEmail value with yours\n primaryEmail: 'liz@example.com',\n name: {\n givenName: 'Elizabeth',\n familyName: 'Smith'\n },\n // Generate a random password string.\n password: Math.random().toString(36)\n };\n try {\n user = AdminDirectory.Users.insert(user);\n console.log('User %s created with ID %s.', user.primaryEmail, user.id);\n } catch (err) {\n // TODO (developer)- Handle exception from the API\n console.log('Failed with error %s', err.message);\n }\n}\n```\n\n### Create alias\n\nThis sample creates an alias (nickname) for a user. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Creates an alias (nickname) for a user.\n * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users.aliases/insert\n */\nfunction createAlias() {\n // TODO (developer) - Replace userEmail value with yours\n const userEmail = 'liz@example.com';\n let alias = {\n alias: 'chica@example.com'\n };\n try {\n alias = AdminDirectory.Users.Aliases.insert(alias, userEmail);\n console.log('Created alias %s for user %s.', alias.alias, userEmail);\n } catch (err) {\n // TODO (developer)- Handle exception from the API\n console.log('Failed with error %s', err.message);\n }\n}\n```\n\n### List all groups\n\nThis sample lists all the groups in the domain. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Lists all the groups in the domain.\n * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups/list\n */\nfunction listAllGroups() {\n let pageToken;\n let page;\n do {\n page = AdminDirectory.Groups.list({\n domain: 'example.com',\n maxResults: 100,\n pageToken: pageToken\n });\n const groups = page.groups;\n if (!groups) {\n console.log('No groups found.');\n return;\n }\n // Print group name and email.\n for (const group of groups) {\n console.log('%s (%s)', group.name, group.email);\n }\n pageToken = page.nextPageToken;\n } while (pageToken);\n}\n```\n\n### Add group member\n\nThis sample adds a user to an existing group in the domain. \nadvanced/adminSDK.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/adminSDK.gs) \n\n```javascript\n/**\n * Adds a user to an existing group in the domain.\n * @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/members/insert\n */\nfunction addGroupMember() {\n // TODO (developer) - Replace userEmail value with yours\n const userEmail = 'liz@example.com';\n // TODO (developer) - Replace groupEmail value with yours\n const groupEmail = 'bookclub@example.com';\n const member = {\n email: userEmail,\n role: 'MEMBER'\n };\n try {\n AdminDirectory.Members.insert(member, groupEmail);\n console.log('User %s added as a member of group %s.', userEmail, groupEmail);\n } catch (err) {\n // TODO (developer)- Handle exception from the API\n console.log('Failed with error %s', err.message);\n }\n}\n```"]]