Functions/Platforms/Get-PASPlatform.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
function Get-PASPlatform {
    <#
.SYNOPSIS
Retrieves details of Vault platforms.

.DESCRIPTION
Request platform configuration information from the Vault.

11.1+ can return details of all platforms.
Filters can be used to retrieve a subset of the platforms

For 9.10+, the "PlatformID" parameter must be used to retrieve details of a single
specified platform from the Vault.

The output contained under the "Details" property differs depending
on which method (9.10+ or 11.1+) is used.

.PARAMETER Active
Filter active/inactive platforms

.PARAMETER PlatformType
Filter regular/group platforms

.PARAMETER Search
Filter platform by search pattern

.PARAMETER PlatformID
The unique ID/Name of the platform.

.EXAMPLE
Get-PASPlatform

Return details of all platforms

.EXAMPLE
Get-PASPlatform -Active $true

Get all active platforms

.EXAMPLE
Get-PASPlatform -Active $true -Search "WIN_"

Get active platforms matching search string "WIN_"

.EXAMPLE
Get-PASPlatform -PlatformID "CyberArk"

Get details of specific platform CyberArk

.NOTES
Minimum CyberArk version 9.10
CyberArk version 11.1 required for Active, PlatformType & Search paramters.

.LINK
https://pspas.pspete.dev/commands/Get-PASPlatform
#>


    [CmdletBinding(DefaultParameterSetName = "11_1")]
    param(
        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "11_1"
        )]
        [boolean]$Active,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "11_1"
        )]
        [ValidateSet("Regular", "Group")]
        [string]$PlatformType,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "11_1"
        )]
        [string]$Search,

        [parameter(
            Mandatory = $true,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "legacy"
        )]
        [Alias("Name")]
        [string]$PlatformID
    )

    BEGIN {
        $MinimumVersion = [System.Version]"9.10"
        $RequiredVersion = [System.Version]"11.1"
    }#begin

    PROCESS {

        If ($PSCmdlet.ParameterSetName -eq "11_1") {

            Assert-VersionRequirement -ExternalVersion $Script:ExternalVersion -RequiredVersion $RequiredVersion

            #Create request URL
            $URI = "$Script:BaseURI/API/Platforms"

            #Get Parameters to include in request
            $boundParameters = $PSBoundParameters | Get-PASParameter

            #Create Query String, escaped for inclusion in request URL
            $queryString = ($boundParameters.keys | ForEach-Object {

                    "$_=$($boundParameters[$_] | Get-EscapedString)"

                }) -join '&'

            #Build URL from base URL
            $URI = "$URI`?$queryString"

        }

        ElseIf ($PSCmdlet.ParameterSetName -eq "legacy") {

            Assert-VersionRequirement -ExternalVersion $Script:ExternalVersion -RequiredVersion $MinimumVersion

            #Create request URL
            $URI = "$Script:BaseURI/API/Platforms/$($PlatformID | Get-EscapedString)"

        }

        #Send request to web service
        $result = Invoke-PASRestMethod -Uri $URI -Method GET -WebSession $Script:WebSession

        If ($result) {

            #11.1 returns result under "platforms" property
            If ($result.Platforms) {

                $result = $result | Select-Object -ExpandProperty Platforms |
                Select-Object @{ Name = 'PlatformID'; Expression = { $_.general.id } }, @{ Name = 'Active'; Expression = { $_.general.active } }, @{ Name = 'Details'; Expression = { [pscustomobject]@{
                            "General"                   = $_.general
                            "properties"                = $_.properties
                            "linkedAccounts"            = $_.linkedAccounts
                            "credentialsManagement"     = $_.credentialsManagement
                            "sessionManagement"         = $_.sessionManagement
                            "privilegedAccessWorkflows" = $_.privilegedAccessWorkflows
                        }
                    }
                }

            }

            #Return Results
            $result |

            Add-ObjectDetail -typename "psPAS.CyberArk.Vault.Platform"

        }

    }#process

    END { }#end

}