close
Amazon Web Services (AWS)

Write a script to list active directories in AWS

Here’s an example of a bash script that lists the active directories in an AWS account using the AWS CLI:

#!/bin/bash

# Set the AWS CLI region
aws configure set default.region us-west-2

# Get a list of all the active directories in the AWS account
active_directories=$(aws ds describe-directories --query 'DirectoryDescriptions[].Name' --output text)

# Loop through the list of active directories
for directory in $active_directories; do
  # Print the name of each active directory
  echo $directory
done

In this example, the AWS CLI is used to retrieve a list of all the active directories in the AWS account, and the bash script loops through that list, printing the name of each active directory. You can modify this script to fit your specific needs, such as filtering the list of active directories based on certain criteria.

Leave a Response