Admin SDK 디렉터리 서비스
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Admin SDK 디렉터리 서비스를 사용하면 Apps Script에서 Admin SDK의 Directory API를 사용할 수 있습니다. 이 API를 통해 Google Workspace 도메인 관리자 (리셀러 포함)는 도메인의 기기, 그룹, 사용자, 기타 항목을 관리할 수 있습니다.
참조
이 서비스에 관한 자세한 내용은 Admin SDK Directory API의 참조 문서를 참고하세요. Apps Script의 모든 고급 서비스와 마찬가지로 Admin SDK 디렉터리 서비스는 공개 API와 동일한 객체, 메서드, 매개변수를 사용합니다. 자세한 내용은 메서드 서명이 결정되는 방식을 참고하세요.
문제를 신고하고 기타 지원을 받으려면 Admin SDK 디렉터리 지원 가이드를 참고하세요.
샘플 코드
아래 샘플 코드에서는 API의 버전 1을 사용합니다.
모든 사용자 나열
이 샘플은 도메인의 모든 사용자를 이름순으로 나열합니다.
사용자 가져오기
이 샘플은 이메일 주소로 사용자를 가져오고 모든 데이터를 JSON 문자열로 로깅합니다.
사용자 추가
이 샘플은 필수 정보만 포함하여 도메인에 새 사용자를 추가합니다. 사용자 필드의 전체 목록은 API의 참고 문서를 참고하세요.
별칭 만들기
이 샘플은 사용자의 별칭 (닉네임)을 만듭니다.
모든 그룹 나열
이 샘플은 도메인의 모든 그룹을 나열합니다.
그룹 구성원 추가
이 샘플은 도메인의 기존 그룹에 사용자를 추가합니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-31(UTC)
[null,null,["최종 업데이트: 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```"]]