

There are more AWS SDK examples available in the [AWS Doc SDK Examples](https://github.com/awsdocs/aws-doc-sdk-examples) GitHub repo.

# Code examples for Directory Service using AWS SDKs
<a name="directory-service_code_examples"></a>

The following code examples show you how to use AWS Directory Service with an AWS software development kit (SDK).

*Actions* are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

**More resources**
+  **[Directory Service Administration Guide](https://docs.aws.amazon.com/directoryservice/latest/admin-guide/what_is.html)** – More information about Directory Service.
+ **[Directory Service API Reference](https://docs.aws.amazon.com/directoryservice/latest/APIReference/Welcome.html)** – Details about all available Directory Service actions.
+ **[AWS Developer Center](https://aws.amazon.com/developer/code-examples/?awsf.sdk-code-examples-product=product%23)** – Code examples that you can filter by category or full-text search.
+ **[AWS SDK Examples](https://github.com/awsdocs/aws-doc-sdk-examples)** – GitHub repo with complete code in preferred languages. Includes instructions for setting up and running the code.

**Contents**
+ [Basics](directory-service_code_examples_basics.md)
  + [Actions](directory-service_code_examples_actions.md)
    + [`DescribeDirectories`](directory-service_example_directory-service_DescribeDirectories_section.md)
    + [`DescribeTrusts`](directory-service_example_directory-service_DescribeTrusts_section.md)

# Basic examples for Directory Service using AWS SDKs
<a name="directory-service_code_examples_basics"></a>

The following code examples show how to use the basics of AWS Directory Service with AWS SDKs. 

**Contents**
+ [Actions](directory-service_code_examples_actions.md)
  + [`DescribeDirectories`](directory-service_example_directory-service_DescribeDirectories_section.md)
  + [`DescribeTrusts`](directory-service_example_directory-service_DescribeTrusts_section.md)

# Actions for Directory Service using AWS SDKs
<a name="directory-service_code_examples_actions"></a>

The following code examples demonstrate how to perform individual Directory Service actions with AWS SDKs. Each example includes a link to GitHub, where you can find instructions for setting up and running the code. 

 The following examples include only the most commonly used actions. For a complete list, see the [AWS Directory Service API Reference](https://docs.aws.amazon.com/directoryservice/latest/APIReference/Welcome.html). 

**Topics**
+ [`DescribeDirectories`](directory-service_example_directory-service_DescribeDirectories_section.md)
+ [`DescribeTrusts`](directory-service_example_directory-service_DescribeTrusts_section.md)

# Use `DescribeDirectories` with a CLI
<a name="directory-service_example_directory-service_DescribeDirectories_section"></a>

The following code examples show how to use `DescribeDirectories`.

------
#### [ CLI ]

**AWS CLI**  
**To get details about your directories**  
The following `describe-directories` example displays details about the specified directory.  

```
aws ds describe-directories \
   --directory-id d-a1b2c3d4e5
```
Output:  

```
{
    "DirectoryDescriptions": [
        {
            "DirectoryId": "d-a1b2c3d4e5",
            "Name": "mydirectory.example.com",
            "ShortName": "mydirectory",
            "Size": "Small",
            "Edition": "Standard",
            "Alias": "d-a1b2c3d4e5",
            "AccessUrl": "d-a1b2c3d4e5.awsapps.com",
            "Stage": "Active",
            "ShareStatus": "Shared",
            "ShareMethod": "HANDSHAKE",
            "ShareNotes": "These are my share notes",
            "LaunchTime": "2019-07-08T15:33:46.327000-07:00",
            "StageLastUpdatedDateTime": "2019-07-08T15:59:12.307000-07:00",
            "Type": "SharedMicrosoftAD",
            "SsoEnabled": false,
            "DesiredNumberOfDomainControllers": 0,
            "OwnerDirectoryDescription": {
                "DirectoryId": "d-b2c3d4e5f6",
                "AccountId": "123456789111",
                "DnsIpAddrs": [
                    "203.113.0.248",
                    "203.113.0.253"
                ],
                "VpcSettings": {
                    "VpcId": "vpc-a1b2c3d4",
                    "SubnetIds": [
                        "subnet-a1b2c3d4",
                        "subnet-d4c3b2a1"
                    ],
                    "AvailabilityZones": [
                        "us-west-2a",
                        "us-west-2c"
                    ]
                }
            }
        }
    ]
}
```
+  For API details, see [DescribeDirectories](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ds/describe-directories.html) in *AWS CLI Command Reference*. 

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**Example 1: This command Obtains information about the directories that belong to this account.**  

```
Get-DSDirectory | Select-Object DirectoryId, Name, DnsIpAddrs, Type
```
**Output:**  

```
DirectoryId  Name           DnsIpAddrs                     Type
-----------  ----           ----------                     ----
d-123456abcd abcd.example.com {172.31.74.189, 172.31.13.145} SimpleAD
d-123456efgh wifi.example.com {172.31.16.108, 172.31.10.56}  ADConnector
d-123456ijkl lan2.example.com {172.31.10.56, 172.31.16.108}  MicrosoftAD
```
+  For API details, see [DescribeDirectories](https://docs.aws.amazon.com/powershell/v4/reference) in *AWS Tools for PowerShell Cmdlet Reference (V4)*. 

**Tools for PowerShell V5**  
**Example 1: This command Obtains information about the directories that belong to this account.**  

```
Get-DSDirectory | Select-Object DirectoryId, Name, DnsIpAddrs, Type
```
**Output:**  

```
DirectoryId  Name           DnsIpAddrs                     Type
-----------  ----           ----------                     ----
d-123456abcd abcd.example.com {172.31.74.189, 172.31.13.145} SimpleAD
d-123456efgh wifi.example.com {172.31.16.108, 172.31.10.56}  ADConnector
d-123456ijkl lan2.example.com {172.31.10.56, 172.31.16.108}  MicrosoftAD
```
+  For API details, see [DescribeDirectories](https://docs.aws.amazon.com/powershell/v5/reference) in *AWS Tools for PowerShell Cmdlet Reference (V5)*. 

------

# Use `DescribeTrusts` with a CLI
<a name="directory-service_example_directory-service_DescribeTrusts_section"></a>

The following code examples show how to use `DescribeTrusts`.

------
#### [ CLI ]

**AWS CLI**  
**To get details about your trust relationships**  
The following `describe-trusts` example displays details about the trust relationships for the specified directory.  

```
aws ds describe-trusts \
   --directory-id d-a1b2c3d4e5
```
Output:  

```
{
    "Trusts": [
        {
            "DirectoryId": "d-a1b2c3d4e5",
            "TrustId": "t-9a8b7c6d5e",
            "RemoteDomainName": "other.example.com",
            "TrustType": "Forest",
            "TrustDirection": "Two-Way",
            "TrustState": "Verified",
            "CreatedDateTime": "2017-06-20T18:08:45.614000-07:00",
            "LastUpdatedDateTime": "2019-06-04T10:52:12.410000-07:00",
            "StateLastUpdatedDateTime": "2019-06-04T10:52:12.410000-07:00",
            "SelectiveAuth": "Disabled"
        }
    ]
}
```
+  For API details, see [DescribeTrusts](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ds/describe-trusts.html) in *AWS CLI Command Reference*. 

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**Example 1: This command gets the information of trust relationships created for specified directory-id.**  

```
Get-DSTrust -DirectoryId d-123456abcd
```
**Output:**  

```
CreatedDateTime          : 7/5/2019 4:55:42 AM
DirectoryId              : d-123456abcd
LastUpdatedDateTime      : 7/5/2019 4:56:04 AM
RemoteDomainName         : contoso.com
SelectiveAuth            : Disabled
StateLastUpdatedDateTime : 7/5/2019 4:56:04 AM
TrustDirection           : One-Way: Incoming
TrustId                  : t-9067157123
TrustState               : Created
TrustStateReason         :
TrustType                : Forest
```
+  For API details, see [DescribeTrusts](https://docs.aws.amazon.com/powershell/v4/reference) in *AWS Tools for PowerShell Cmdlet Reference (V4)*. 

**Tools for PowerShell V5**  
**Example 1: This command gets the information of trust relationships created for specified directory-id.**  

```
Get-DSTrust -DirectoryId d-123456abcd
```
**Output:**  

```
CreatedDateTime          : 7/5/2019 4:55:42 AM
DirectoryId              : d-123456abcd
LastUpdatedDateTime      : 7/5/2019 4:56:04 AM
RemoteDomainName         : contoso.com
SelectiveAuth            : Disabled
StateLastUpdatedDateTime : 7/5/2019 4:56:04 AM
TrustDirection           : One-Way: Incoming
TrustId                  : t-9067157123
TrustState               : Created
TrustStateReason         :
TrustType                : Forest
```
+  For API details, see [DescribeTrusts](https://docs.aws.amazon.com/powershell/v5/reference) in *AWS Tools for PowerShell Cmdlet Reference (V5)*. 

------