本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
ListOrganizationalUnitsForParent 搭配 AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 ListOrganizationalUnitsForParent。
- .NET
-
- 適用於 .NET 的 SDK
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 using System; using System.Threading.Tasks; using Amazon.Organizations; using Amazon.Organizations.Model; /// <summary> /// Lists the AWS Organizations organizational units that belong to an /// organization. /// </summary> public class ListOrganizationalUnitsForParent { /// <summary> /// Initializes the Organizations client object and then uses it to /// call the ListOrganizationalUnitsForParentAsync method to retrieve /// the list of organizational units. /// </summary> public static async Task Main() { // Create the client object using the default account. IAmazonOrganizations client = new AmazonOrganizationsClient(); var parentId = "r-0000"; var request = new ListOrganizationalUnitsForParentRequest { ParentId = parentId, MaxResults = 5, }; var response = new ListOrganizationalUnitsForParentResponse(); try { do { response = await client.ListOrganizationalUnitsForParentAsync(request); response.OrganizationalUnits.ForEach(u => DisplayOrganizationalUnit(u)); if (response.NextToken is not null) { request.NextToken = response.NextToken; } } while (response.NextToken is not null); } catch (Exception ex) { Console.WriteLine(ex.Message); } } /// <summary> /// Displays information about an Organizations organizational unit. /// </summary> /// <param name="unit">The OrganizationalUnit for which to display /// information.</param> public static void DisplayOrganizationalUnit(OrganizationalUnit unit) { string accountInfo = $"{unit.Id} {unit.Name}\t{unit.Arn}"; Console.WriteLine(accountInfo); } }-
如需 API 詳細資訊,請參閱《適用於 .NET 的 AWS SDK API 參考》中的 ListOrganizationalUnitsForParent。
-
- CLI
-
- AWS CLI
-
擷取父 OU 或根帳戶中的 OU 清單
下列範例示範如何取得指定根帳戶中的 OU 清單:
aws organizations list-organizational-units-for-parent --parent-idr-examplerootid111輸出顯示指定的根帳戶包含兩個 OU 並顯示每個的詳細資訊:
{ "OrganizationalUnits": [ { "Name": "AccountingDepartment", "Arn": "arn:aws:organizations::o-exampleorgid:ou/r-examplerootid111/ou-examplerootid111-exampleouid111" }, { "Name": "ProductionDepartment", "Arn": "arn:aws:organizations::o-exampleorgid:ou/r-examplerootid111/ou-examplerootid111-exampleouid222" } ] }-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 ListOrganizationalUnitsForParent
。
-
如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 AWS Organizations 搭配 AWS SDK 使用。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。
ListAccounts
ListPolicies