thycotic-ps / thycotic.secretserver

PowerShell module for automating with Thycotic Secret Server REST API
https://thycotic-ps.github.io/thycotic.secretserver
MIT License
68 stars 22 forks source link

Get-tssFolder does not pull ChildFolders when using -GetChildren #334

Closed ervinpeter closed 1 year ago

ervinpeter commented 1 year ago

Verified issue does not already exist?

Yes

What error did you receive

When running the command and using the -GetChildren parameter the object returns as blank. In order to retrieve the childFolders you must pipe the command and expand the property. For example, get-tssFolder -TssSession $session -Id 13 -GetChildren | Select-Object -ExpandProperty ChildFolders

Please run the command using -Verbose

get-tssFolder -TssSession $session -Id 13 -GetChildren -Verbose VERBOSE: Performing the operation GET https://xxxx.secretservercloud.com/api/v1/folders/13?getAllChildren=True&includeAssociatedTemplates=False

FolderId FolderName FolderPath InheritSecretPolicy InheritPermissions ParentFolderId


13 US \XXX\MF\US True False 11

Provide a test case or steps to reproduce

get-tssFolder -TssSession $session -Id 13 -GetChildren

Expected behavior

The expected behavior is

PS C:\Users\SecretServer> get-tssFolder -TssSession $session -Id 13 -GetChildren

FolderId FolderName FolderPath InheritSecretPolicy InheritPermissions ParentFolderId


139 PFSLAB \XXX\MF\US\PFSLAB True False 13 28 Regional Intergr \XXX\MF\US\Regional True False 13 29 USCB \XXX\MF\US\USCB True True 13 475 USTC \XXX\MF\US\USTC True True 13 496 USTK \XXX\MF\US\USTK True True 13

What Edition of Secret Server?

Platinum

What version of Secret Server

EA release

What PowerShell host was used when producing this error

VS Code (terminal)

PowerShell Host Version

Name Value


PSVersion 5.1.19041.2673
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.2673
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1


jagger commented 1 year ago

the child folders are included as a property called ChildFolders The value is not output by default, but if you $result | select-object -property * it will be shown

The API is a bit literal here as most people will expect to get a list of all subfolders from this, the endpoint only returns the top level of children. This may be what you are looking for

function get-TssFolderTree   { [CmdletBinding()]
    param(
    [Parameter(Position = 0, mandatory = $true)]
    [Thycotic.PowerShell.Authentication.Session]$TssSession,
    [Parameter(Position = 1)]
    [int]$ParentFolderID = -1
    )

    $children = search-tssfolder -TssSession $tsssession -ParentFolderId $ParentFolderID
    if ($ParentFolderID -gt 0) { $list = $children.FolderId + $ParentFolderID } else { $list = $children.FolderId }

    return get-tssfolder -TssSession $TssSession -Id $list | Sort-Object FolderPath

    }
jagger commented 1 year ago

Working as intended, workaround provided