2

When running a cmdlet like Get-WKSWorkspaces, it will return a set of properties about your workspaces (e.g. WorkspaceID, Username, SubnetID, BundleID, etc.), but not everything you see in the AWS GUI. I am specifically trying to pull things like Running Mode, Compute Type, and Creation Time as well, but can't seem to find where to pull it.

In my research, I got up to the point where I was using $AWSHistory to try and dig deeper into the data returned from my previous cmdlets, but have definitely hit a wall and can't seem to get around it.

I do have a partial command that is giving me most of the output I need:

$region = Get-DefaultAWSRegion
$lastuserconnect = Get-WKSWorkspacesConnectionStatus | Select LastKnownUserConnectionTimestamp

Get-WKSWorkspace -ProfileName ITSLayer1-053082227562-Profile | Select WorkspaceID, UserName, BundleID, DirectoryID, 
@{Name="Region"; Expression={$region.Region}}, 
@{Name="LastKnownUserConnect"; Expression= 
{$lastuserconnect.LastKnownUserConnectionTimestamp}}

Update for posterity: Actually got something decent to come out here. It's slow, but it renders in a table format pretty well and includes a bit at the start to select your AWS region.

Suggestions for improvement include:

  1. Automatically switching the Region select to get all workspaces from the main Regions we use
  2. Cleaning the lines up so it's easier to read
  3. Getting the region to automatically append the filename so it doesn't overwrite your file every time (it's in there but broken at the moment...still pops out a file with 'workspace_properties.csv' as the name)
  4. Optimizing the script because it's pretty slow

    $lastuserconnect = Get-WKSWorkspacesConnectionStatus -ProfileName $profile $defaultregion = Get-DefaultAWSRegion $showallregions = Get-AWSRegion $exportpath = "" + $env:USERPROFILE + "\workspace_properties" + $defaultregion.Region + ".csv"

    $showallregions | Format-Table

    $setregion = Read-Host -Prompt 'AWS Region'

    Clear-DefaultAWSRegion Set-DefaultAWSRegion $setregion

    Get-WKSWorkspace -ProfileName $profile | Select WorkspaceID, UserName, BundleID, DirectoryID, @{Name="ComputeType"; Expression={$.WorkspaceProperties.ComputeTypeName}}, @{Name="RunningMode"; Expression={$.WorkspaceProperties.RunningMode}}, @{Name="Region"; Expression={$defaultregion.Region}}, @{Name="LastKnownUserConnect"; Expression={$_ | foreach {$lastuserconnect = Get-WKSWorkspacesConnectionStatus -ProfileName $profile -WorkspaceId $_.WorkspaceId; echo $lastuserconnect.LastKnownUserConnectionTimestamp}}} | Export-Csv $exportpath

zasmith
  • 23
  • 4
  • Here, $lastuserconnect.LastKnownUserConnectionTimestamp is actually bunch of Timestamps that does not list the timestamp for the specific workspace – Ketanbhut May 31 '19 at 18:43
  • Literally just found this out myself like 2 mins ago. Currently working it out. Good catch. Thanks! – zasmith May 31 '19 at 19:00
  • I've hit a brick wall. The below solution doesn't format to a CSV, and mine above does, but I can't get that $lastuserconnect to display right. Any tips? – zasmith Jun 04 '19 at 15:19
  • so in your above code.. I see that you store LastKnownUserConnect as this: -- is that correct? @{Name="LastKnownUserConnect"; Expression={$_ | foreach {$lastuserconnect = Get-WKSWorkspacesConnectionStatus -ProfileName $profile -WorkspaceId $_.WorkspaceId; echo $lastuserconnect.LastKnownUserConnectionTimestamp}} – Ketanbhut Jun 06 '19 at 16:49

2 Answers2

0

From looking at the docs it appears what you are looking for in the property WorkspaceProperties which contains an Amazon.WorkSpaces.Model.WorkspaceProperties object with the following properties:

ComputeTypeName Amazon.WorkSpaces.Compute
RootVolumeSizeGib System.Int32
RunningMode Amazon.WorkSpaces.RunningMode
RunningModeAutoStopTimeoutInMinutes System.Int32
UserVolumeSizeGib System.Int32

Not sure about the CreationTime though...

Matt
  • 45,022
  • 8
  • 78
  • 119
  • Can you point me to documentation where I can learn out to extract the data from objects like these? There is a definite gap in my Powershell knowledge here. – zasmith May 31 '19 at 17:18
  • Should be able to use dot notation just like you already have done with last user connect. Nothing fancy required – Matt May 31 '19 at 17:20
0

Here is an example of fetching those properties you are looking for:

Get-WKSWorkspace | foreach {
    $connectionStatus = Get-WKSWorkspacesConnectionStatus -WorkspaceId $_.WorkspaceId; 
    echo "";
    echo "==> About $($_.WorkspaceId)";
    echo "Last State Check: $($connectionStatus.ConnectionStateCheckTimestamp)"; 
    echo "User Last Active: $($connectionStatus.LastKnownUserConnectionTimestamp)";
    echo "Directory: $($_.DirectoryId)";
    echo "Compute: $($_.WorkspaceProperties.ComputeTypeName)"; 
    echo "Running mode $($_.WorkspaceProperties.RunningMode)";
    echo "State $($_.State)"
}

I don't see a 'Creation Time' on workspace on the console either.

[edit] I believe you are looking for a way to export these info, may be below code will help:

[System.Collections.ArrayList]$output=@()
Get-WKSWorkspace | foreach {
    $connectionStatus = Get-WKSWorkspacesConnectionStatus -WorkspaceId $_.WorkspaceId; 
    $bunch = [pscustomobject]@{
        WorkspaceId = $_.WorkspaceId
        LastStateCheck=$connectionStatus.ConnectionStateCheckTimestamp
        UserLastActive=$connectionStatus.LastKnownUserConnectionTimestamp
        Directory= $_.DirectoryId
        Compute=$_.WorkspaceProperties.ComputeTypeName
        Runningmode= $_.WorkspaceProperties.RunningMode
        State= $_.State
    }
    $output.Add($bunch)|Out-Null
}

$output | Export-Csv -NoType c:\dd.csv
Ketanbhut
  • 476
  • 2
  • 11
  • I will have to go back and explain that it's not available. They are most likely looking for 'workspace age', so I am wondering if we can put an initial creation date in a tag or something so it's tracked that way. Of course, that is only so effective because we rebuild them from time to time. In any case, thanks for your assistance! – zasmith Jun 03 '19 at 13:00