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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
function Get-PASPlatform {
    <#
.SYNOPSIS
Retrieves details of Vault platforms.

.DESCRIPTION
Request platform configuration information from the Vault.

11.4+ can return details of target, dependent, group & rotational group platforms,
with additional filters available for target group queries.
11.1+ can return details of all target platforms.
Limited filters can be used to retrieve a subset of the platforms
For 9.10+, the "PlatformID" parameter is 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+,11.1+ or 11.4+) is used, and which platform type is queried.
!Note: When specifying PlatformID:
! if the platform properties contain a semicolon (';'), the API may not return the complete value.
! noted for ChangeCommand, ReconcileCommand & ConnectionCommand properties

.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.

.PARAMETER DependentPlatform
Specify to return details of dependent platforms

.PARAMETER GroupPlatform
Specify to return details of group platforms

.PARAMETER RotationalGroup
Specify to return details of rotational group platforms

.PARAMETER SystemType
Filter target platforms for specific system type

.PARAMETER PeriodicVerify
Filter target platforms by periodic verification configuration

.PARAMETER ManualVerify
Filter target platforms by manual verification configuration

.PARAMETER PeriodicChange
Filter target platforms by periodic change configuration

.PARAMETER ManualChange
Filter target platforms by manual change configuration

.PARAMETER AutomaticReconcile
Filter target platforms by automatic reconciliation configuration

.PARAMETER ManualReconcile
Filter target platforms by manual reconciliation configuration

.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

.EXAMPLE
Get-PASPlatform -GroupPlatform

Get details of all group platforms

.EXAMPLE
Get-PASPlatform -RotationalGroup

Get details of all rotational group platforms

.EXAMPLE
Get-PASPlatform -DependentPlatform

Get details of all dependent platforms

.EXAMPLE
Get-PASPlatform -Active $false -SystemType Windows

Get details of all deactivated Windows platforms

.EXAMPLE
Get-PASPlatform -Active $true -SystemType '*NIX' -AutomaticReconcile $true

Get details of all active Unix platforms configured for automatic reconciliation.

.NOTES
Minimum CyberArk version 9.10
CyberArk version 11.1 required for Active, PlatformType & Search parameters.
CyberArk version 11.4 required for extended filters for target platforms,
and requests for dependent, group & rotational group platforms

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


    [CmdletBinding(DefaultParameterSetName = "targets")]
    param(
        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "11_1"
        )]
        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "targets"
        )]
        [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,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "dependents"
        )]
        [switch]$DependentPlatform,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "groups"
        )]
        [switch]$GroupPlatform,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "rotationalGroups"
        )]
        [switch]$RotationalGroup,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "targets"
        )]
        [string]$SystemType,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "targets"
        )]
        [boolean]$PeriodicVerify,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "targets"
        )]
        [boolean]$ManualVerify,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "targets"
        )]
        [boolean]$PeriodicChange,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "targets"
        )]
        [boolean]$ManualChange,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "targets"
        )]
        [boolean]$AutomaticReconcile,

        [parameter(
            Mandatory = $false,
            ValueFromPipelinebyPropertyName = $true,
            ParameterSetName = "targets"
        )]
        [boolean]$ManualReconcile

    )

    BEGIN {

    }#begin

    PROCESS {

        switch ($PSCmdlet.ParameterSetName) {

            "11_1" {

                Assert-VersionRequirement -RequiredVersion 11.1

                #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 | ConvertTo-QueryString

                If ($null -ne $queryString) {
                    #Build URL from base URL
                    $URI = "$URI`?$queryString"
                }

                break

            }

            "legacy" {

                Assert-VersionRequirement -RequiredVersion 9.10

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

                break

            }

            "targets" {

                Assert-VersionRequirement -RequiredVersion 11.4

                $URI = "$Script:BaseURI/API/Platforms/$($PSCmdlet.ParameterSetName)"

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

                $queryString = $boundParameters | ConvertTo-FilterString | ConvertTo-QueryString

                If ($null -ne $queryString) {

                    $URI = "$URI`?$queryString"

                }

                break

            }

            default {

                Assert-VersionRequirement -RequiredVersion 11.4

                $URI = "$Script:BaseURI/API/Platforms/$($PSCmdlet.ParameterSetName)"

                break

            }

        }

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

        If ($null -ne $result) {

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

                $result = $result | Select-Object -ExpandProperty Platforms

                switch ($PSCmdlet.ParameterSetName) {

                    "11_1" {
                        $result = $result |
                        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
                                }
                            }
                        }

                        break
                    }

                    "targets" {
                        $result = $result |
                        Select-Object PlatformID, Active, @{ Name = 'Details'; Expression = { [pscustomobject]@{
                                    "ID"                          = $_.ID
                                    "Name"                        = $_.Name
                                    "SystemType"                  = $_.SystemType
                                    "AllowedSafes"                = $_.AllowedSafes
                                    "CredentialsManagementPolicy" = $_.CredentialsManagementPolicy
                                    "PrivilegedAccessWorkflows"   = $_.PrivilegedAccessWorkflows
                                    "PrivilegedSessionManagement" = $_.PrivilegedSessionManagement
                                }
                            }
                        }
                        break
                    }

                    "groups" {
                        $result = $result |
                        Select-Object PlatformID, Active, @{ Name = 'Details'; Expression = { [pscustomobject]@{
                                    "ID"   = $_.ID
                                    "Name" = $_.Name
                                }
                            }
                        }
                        break
                    }

                    "dependents" {
                        $result = $result |
                        Select-Object PlatformID, @{ Name = 'Details'; Expression = { [pscustomobject]@{
                                    "ID"                            = $_.ID
                                    "Name"                          = $_.Name
                                    "NumberOfLinkedTargetPlatforms" = $_.NumberOfLinkedTargetPlatforms
                                    "CredentialsManagementPolicy"   = $_.CredentialsManagementPolicy
                                }
                            }
                        }
                        break
                    }

                    "rotationalGroups" {
                        $result = $result |
                        Select-Object PlatformID, Active, @{ Name = 'Details'; Expression = { [pscustomobject]@{
                                    "ID"          = $_.ID
                                    "Name"        = $_.Name
                                    "GracePeriod" = $_.GracePeriod
                                }
                            }
                        }
                        break
                    }

                }

            }

            #Return Results
            $result |

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

        }

    }#process

    END { }#end

}