SecretManagement.PleasantPasswordServer.Extension/Private/Get-SecretFolder.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function Get-SecretFolder
{
    <#
    .SYNOPSIS
        Get the folderstructure for a single secret
    .DESCRIPTION
        Get the folderstructure for a single secret
    .EXAMPLE
        $param = @{
            ServerURL = '<your server url>'
            Token = '<your token>'
            GroupID = '<your group id>'
        }

        PS C:\> Get-SecretFolder @param
        Get the folderstructure for a single secret
    .INPUTS
        System.String,
        System.String
        System.String
    .OUTPUTS
        System.String[]
    .NOTES
        Author: Constantin Hager
        Date: 2021-03-17
    #>


    param
    (
        $ServerURL,
        $Token,
        $GroupID
    )

    if ($GroupID -eq "00000000-0000-0000-0000-000000000000")
    {
        $FolderString = 'Root'
        return
    }

    $headers = @{
        "Accept"        = "application/json"
        "Authorization" = "$Token"
    }

    $Params = @{
        Method      = 'GET'
        Uri         = "$ServerURL/api/v5/rest/folders/$($GroupId)?recurseLevel=0"
        Headers     = $headers
        ContentType = 'application/json'
    }
    $FolderMetadata = Invoke-RestMethod @Params

    $Folderstring = [string]::Concat($FolderMetadata.Name, '/', $FolderString)
    Get-SecretFolder -ServerURL $ServerURL -Token $Token -GroupID $FolderMetadata.ParentId
    return $FolderString
}