Skip to content

Export Amazon WorkSpaces Details with PowerShell: A Simple and Effective Method


Amazon WorkSpaces is a fully managed, secure desktop-as-a-service (DaaS) solution that lets you provision and manage cloud-based virtual desktops for your users. You can use the AWS Tools for PowerShell to interact with the Amazon WorkSpaces API and perform various operations on your WorkSpaces, such as creating, modifying, deleting, rebooting, rebuilding, and restoring them.

One of the common tasks that you might want to perform on your WorkSpaces is to export their details to a file or a report. This can help you gain insights into your WorkSpaces deployment, such as the number, status, configuration, and usage of your WorkSpaces. You can also use the exported data for auditing, compliance, billing, or troubleshooting purposes.

In this article, I will show you how to use PowerShell to easily export Amazon WorkSpaces details using the Get-WKSWorkspace cmdlet. This cmdlet allows you to retrieve information about your WorkSpaces, such as their bundle identifier, directory identifier, user name, workspace ID, state, IP address, and connection status. You can also filter the results by using various parameters, such as -BundleId, -DirectoryId, -UserName, or -WorkspaceId.

By the end of this article, you will be able to export Amazon WorkSpaces details using PowerShell easily and efficiently. You will also learn how to combine the WorkSpaces data with other information from Active Directory and virtual private cloud (VPC) properties, as well as how to format and save the output to a CSV or HTML file.

Before we can get the data exported, we must have required configuration/pre-requisites :

  • IAM role with minimum permission to describe WorkSpaces in a Account
  • A terminal or command line access to execute commands. Preferred would be local system however, you can use AWS Cloud Shell to perform these actions.

Let’s go through below steps to get WorkSpaces data exported.

Option 1: Use terminal on desktop to export WorkSpaces details.

  1. Setup IAM role with minimum permissions or use AmazonWorkSpacesAdmin role . At minimum create a new role or add below permission to existing role: 
    “workspaces:DescribeWorkspaces”
  2. Configure the AWS Security credentials aquired from IAM federated role or via instance profile or by creating an IAM user. You will need to have following information as part of credentials:       
    Accesskey       
    Secretkey       
    SessionToken [Optional if direct user credentials are used]

    Once you obtained above information, use either of below options to set AWS IAM credentials for use.
    • For current PowerShell session only:
      $Env:AWS_ACCESS_KEY_ID='your Access Key'
      $Env:AWS_SECRET_ACCESS_KEY='your Secret Key'
      $Env:AWS_SESSION_TOKEN='Your Session Token'
    • For current PowerShell session only:
      Set-AWSCredential -AccessKey 'YourAccesskeyhere' -SecretKey 'YourSecretKey' -SessionToken 'YourSessionToken' #Optional Set Default AWS region Set-DefaultAWSRegion -Region 'YourWorkSpaceRegion'
  3. Install AWS tools for PowerShell
    Install-Module -Name AWS.Tools.Installer -AcceptLicense -SkipPublisherCheck
  4. Install WorkSpaces module for use in this case
    Install-AWSToolsModule AWS.Tools.WorkSpaces -cleanup -Confirm:$false
  5. Export WorkSpaces data using Get-WKSWorkspace command
    #Get All WorkSpaces data
    Get-WKSWorkspace | Export-Csv AllWorkSpaces.csv
    #Get WorkSpaces data for a speicific directory
    Get-WKSWorkspace -DirectoryID 'Your Directory ID' | Export-Csv SpecificDirectoryWorkSpaces.csv<br>
#Examples

Get-WKSWorkspace

ComputerName     BundleId         IpAddress        Encrypted  State        SubnetId           UserName       WorkspaceId
------------     --------         ---------        ---------  -----        --------           --------       -----------
USER-SPNO6L8888  wsb-8wgvqc69p    10.10.23.247     False      STOPPED      subnet-085ae148c9… WKSPCBA05      ws-4djx4lsph
WSAMZN-6PFC1M6P  wsb-fb2xfp6e8    10.10.22.56      False      STOPPED      subnet-082be0114e… WKSPSCA10      ws-f6ghg9g6c
WSAMZN-J054DTSE  wsb-4qyzfv0qr    10.10.22.101     False      STOPPED      subnet-082be0114e… WKSPCBA02      ws-hh3fw9p9t
WSAMZN-CUHQ0BLN  wsb-8vbljg4o6    10.10.22.173     False      STOPPED      subnet-082be0114e… WKSPPCOIP01    ws-187js9lcj

PS C:\ Get-WKSWorkspace -DirectoryId d-976751d3d2

ComputerName     BundleId         IpAddress        Encrypted  State        SubnetId           UserName       WorkspaceId
------------     --------         ---------        ---------  -----        --------           --------       -----------
USER-SPNO6L8888  wsb-8wgvqcfsp    10.10.23.247     False      STOPPED      subnet-085ae148c9… WKSPCBA05      ws-4djx4kfwh

Option 2: Use AWS CloudShell to get the required data

You might not be aware that AWS CloudShell allows installation of many packages and also supports PowerShell .net Core.

To use PowerShell in AWS CloudShell simply connect to AWS console and launch AWS CloudShell. Once inside enter pwsh . If pwsh doesn’t work install pwsh using Microsoft link and command for installing on AWS CloudShell is

sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v7.4.0/powershell-7.4.0-1.rh.x86_64.rpm

At prompt you can use the same tools if PowerShell tools are not installed then refer to installation session of this article.