本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
ListOrganizationalUnitsForParent
搭配 AWS SDK或 使用 CLI
下列程式碼範例示範如何使用 ListOrganizationalUnitsForParent
。
- .NET
-
- AWS SDK for .NET
-
注意
還有更多功能 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詳細資訊,請參閱 AWS SDK for .NET API 參考ListOrganizationalUnitsForParent中的 。
-
- CLI
-
- AWS CLI
-
擷取父 OU 或根OUs中的 清單
下列範例示範如何在指定的根OUs目錄中取得 的清單:
aws organizations list-organizational-units-for-parent --parent-id
r-examplerootid111
輸出顯示指定的根包含兩個OUs,並顯示每個項目的詳細資訊:
{ "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