This repository was archived by the owner on Apr 18, 2024. It is now read-only.
forked from dnlrv/PlatformPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatformPlus.ps1
More file actions
4898 lines (4029 loc) · 177 KB
/
PlatformPlus.ps1
File metadata and controls
4898 lines (4029 loc) · 177 KB
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#######################################
#region ### MAJOR FUNCTIONS ###########
#######################################
###########
#region ### Verify-PlatformConnection # Check to ensure you are connected to the tenant before proceeding.
###########
function global:Verify-PlatformConnection
{
<#
.SYNOPSIS
This function verifies you have an active connection to a Delinea Platform Tenant.
.DESCRIPTION
This function verifies you have an active connection to a Delinea Platform Tenant. It checks for the existance of a $PlatformConnection
variable to first check if a connection has been made, then it makes a Security/whoami RestAPI call to ensure the connection is active and valid.
This function will store a date any only check if the last attempt was made more than 5 minutes ago. If the last verify attempt occured
less than 5 minutes ago, the check is skipped and a valid connection is assumed. This is done to prevent an overbundence of whoami calls to the
Platform.
.INPUTS
None. You can't redirect or pipe input to this function.
.OUTPUTS
This function only throws an error if there is a problem with the connection.
.EXAMPLE
C:\PS> Verify-PlatformConnection
This function will not return anything if there is a valid connection. It will throw an exception if there is no connection, or an
expired connection.
#>
if ($PlatformConnection -eq $null)
{
throw ("There is no existing `$PlatformConnection. Please use Connect-DelineaPlatform to connect to your Delinea tenant. Exiting.")
}
else
{
Try
{
# check to see if Lastwhoami is available
if ($global:LastWhoamicheck)
{
# if it is, check to see if the current time is less than 5 minute from its previous whoami check
if ($(Get-Date).AddMinutes(-5) -lt $global:LastWhoamicheck)
{
# if it has been less than 5 minutes, assume we're still connected
return
}
}# if ($global:LastWhoamicheck)
$uri = ("https://{0}/Security/whoami" -f $global:PlatformConnection.PodFqdn)
# calling Security/whoami
$WhoamiResponse = Invoke-RestMethod -Method Post -Uri $uri @global:SessionInformation
# if the response was successful
if ($WhoamiResponse.Success)
{
# setting the last whoami check to reduce frequent whoami calls
$global:LastWhoamicheck = (Get-Date)
return
}
else
{
throw ("There is no active, valid Tenant connection. Please use Connect-DelineaPlatform to re-connect to your Delinea tenant. Exiting.")
}
}# Try
Catch
{
throw ("There is no active, valid Tenant connection. Please use Connect-DelineaPlatform to re-connect to your Delinea tenant. Exiting.")
}
}# else
}# function global:Verify-PlatformConnection
#endregion
###########
###########
#region ### global:Invoke-PlatformAPI # Invokes RestAPI using either the interactive session or the bearer token
###########
function global:Invoke-PlatformAPI
{
<#
.SYNOPSIS
This function will provide an easy way to interact with any RestAPI endpoint in a Delinea PAS tenant.
.DESCRIPTION
This function will provide an easy way to interact with any RestAPI endpoint in a Delinea PAS tenant. This function requires an existing, valid $PlatformConnection
to exist. At a minimum, the APICall parameter is required.
.PARAMETER APICall
Specify the RestAPI endpoint to target. For example "Security/whoami" or "ServerManage/UpdateResource".
.PARAMETER Body
Specify the JSON body payload for the RestAPI endpoint.
.INPUTS
None. You can't redirect or pipe input to this function.
.OUTPUTS
This function outputs as PSCustomObject with the requested data if the RestAPI call was successful.
.EXAMPLE
C:\PS> Invoke-PlatfromAPI -APICall Security/whoami
This will attempt to reach the Security/whoami RestAPI endpoint to the currently connected PAS tenant. If there is a valid connection, basic
information about the connected user will be returned as output.
.EXAMPLE
C:\PS> Invoke-PlatformAPI -APICall UserMgmt/ChangeUserAttributes -Body ( @{CmaRedirectedUserUuid=$normalid;ID=$adminid} | ConvertTo-Json)
This will attempt to set MFA redirection on a user recognized by the PAS tenant. The body in this example is a PowerShell HastTable converted into a JSON block.
The $normalid variable contains the UUID of the user to redirect to, and the $adminid is the UUID of the user who needs the redirect.
.EXAMPLE
C:\US> Invoke-PlatformAPI -APICall Collection/GetMembers -Body '{"ID":"aaaaaaaa-0000-0000-0000-eeeeeeeeeeee"}'
This will attempt to get the members of a Set via that Set's UUID. In this example, the JSON Body payload is already in JSON format.
#>
param
(
[Parameter(Position = 0, Mandatory = $true, HelpMessage = "Specify the API call to make.")]
[System.String]$APICall,
[Parameter(Position = 1, Mandatory = $false, HelpMessage = "Specify the JSON Body payload.")]
[System.String]$Body
)
# verifying an active platform connection
Verify-PlatformConnection
# setting the url based on our PlatformConnection information
$uri = ("https://{0}/{1}" -f $global:PlatformConnection.PodFqdn, $APICall)
# Try
Try
{
Write-Debug ("Uri=[{0}]" -f $uri)
Write-Debug ("Body=[{0}]" -f $Body)
# making the call using our a Splat version of our connection
$Response = Invoke-RestMethod -Method Post -Uri $uri -Body $Body @global:SessionInformation
# if the response was successful
if ($Response.Success)
{
# return the results
return $Response.Result
}
else
{
# otherwise throw what went wrong
Throw $Response.Message
}
}# Try
Catch
{
$LastError = [PlatformAPIException]::new("A PlatformAPI error has occured. Check `$LastError for more information")
$LastError.APICall = $APICall
$LastError.Payload = $Body
$LastError.Response = $Response
$LastError.ErrorMessage = $_.Exception.Message
$global:LastError = $LastError
Throw $_.Exception
}
}# function global:Invoke-PlatformAPI
#endregion
###########
###########
#region ### global:Query-VaultRedRock # Make an SQL RedRock query to the tenant
###########
function global:Query-VaultRedRock
{
<#
.SYNOPSIS
This function makes a direct SQL query to the SQL tables of the connected Delinea PAS tenant.
.DESCRIPTION
This function makes a direct SQL query to the SQL tables of the connected Delinea PAS tenant. Most SELECT SQL queries statements will work to query data.
.PARAMETER SQLQuery
The SQL Query to run. Most SELECT queries will work, as well as most JOIN, CASE, WHERE, AS, COUNT, etc statements.
.INPUTS
None. You can't redirect or pipe input to this function.
.OUTPUTS
This function outputs a PSCustomObject with the requested data.
.EXAMPLE
C:\PS> Query-VaultRedRock -SQLQuery "SELECT * FROM Sets"
This query will return all rows and all property fields from the Sets table.
.EXAMPLE
C:\PS> Query-VaultRedRock -SQLQuery "SELECT COUNT(*) FROM Servers"
This query will return a count of all the rows in the Servers table.
.EXAMPLE
C:\PS> Query-VaultRedRock -SQLQuery "SELECT Name,User AS AccountName FROM VaultAccount LIMIT 10"
This query will return the Name property and the User property (renamed AS AccountName) from the VaultAccount table and limiting those results to 10 rows.
#>
param
(
[Parameter(Position = 0, Mandatory = $true, HelpMessage = "The SQL query to execute.")]
[System.String]$SQLQuery
)
# verifying an active platform connection
Verify-PlatformConnection
# Set Arguments
$Arguments = @{}
#$Arguments.PageNumber = 1
#$Arguments.PageSize = 10000
#$Arguments.Limit = 10000 # removing this as it caps results to 10k
$Arguments.SortBy = ""
$Arguments.Direction = "False"
$Arguments.Caching = 0
$Arguments.FilterQuery = "null"
# Build the JsonQuery string
$JsonQuery = @{}
$JsonQuery.Script = $SQLQuery
$JsonQuery.Args = $Arguments
# make the call, using whatever SQL statement was provided
$RedRockResponse = Invoke-PlatformAPI -APICall RedRock/query -Body ($JsonQuery | ConvertTo-Json)
# return the rows that were queried
return $RedRockResponse.Results.Row
}# function global:Query-VaultRedRock
#endregion
###########
###########
#region ### global:Set-PlatformConnection # Changes the PlatformConnection information to another connected tenant.
###########
function global:Set-PlatformConnection
{
<#
.SYNOPSIS
This function will change the currently connected tenant to another actively connected tenant.
.DESCRIPTION
This function will change the currently connected tenant to another actively connected tenant. This function is only needed if you are working with two or
more PAS tenants. For example, if you are working on mycompanydev.my.centrify.net and also on mycompanyprod.my.centrify.net, this function can help
you switch connections between the two without having to reauthenticate to each one during the switch. Each connection must still initially be completed
once via the Connect-DelineaPlatform function.
.PARAMETER PodFqdn
Specify the tenant's URL to switch to. For example, mycompany.my.centrify.net
.INPUTS
None. You can't redirect or pipe input to this function.
.OUTPUTS
This script only returns $true on a successful switch, or $false if the specified PodFqdn was not found.
.EXAMPLE
C:\PS> Set-PlatformConnection -PodFqdn mycompanyprod.my.centrify.net
This will switch your existing $PlatformConnection and $SessionInformation variables to the specified tenant. In this
example, the login for mycopanyprod.my.centrify.net must have already been completed via the Connect-DelineaPlatform cmdlet.
#>
param
(
[Parameter(Position = 0, Mandatory = $true, HelpMessage = "The PodFqdn to switch to for authentication.")]
[System.String]$PodFqdn
)
# if the $PlatformConnections contains the podFqdn in it's list
if ($thisconnection = $global:PlatformConnections | Where-Object {$_.PodFqdn -eq $PodFqdn})
{
# change the PlatformConnection and SessionInformation to the requested tenant
$global:SessionInformation = $thisconnection.SessionInformation
$global:PlatformConnection = $thisconnection.PlatformConnection
return $true
}# if ($thisconnection = $global:PlatformConnections | Where-Object {$_.PodFqdn -eq $PodFqdn})
else
{
return $false
}
}# function global:Set-PlatformConnection
#endregion
###########
###########
#region ### global:Search-PlatformDirectory # Searches existing directories for principals or roles and returns the Name and ID by like searches
###########
function global:Search-PlatformDirectory
{
<#
.SYNOPSIS
This function will retrieve the UUID of the specified principal from all reachable tenant directories.
.DESCRIPTION
This function will retrieve the UUID of the specified principal from all reachable tenant directories. The searches made
by principal is a like search, so any matching query will be returned. For example, searching for -Role "System" will
return any Role with "System" in the name.
.PARAMETER User
Search for a user by their User Principal Name. For example, "person@domain.com"
.PARAMETER Group
Search for a group by their Group and domain. For example, "WidgetAdmins@domain.com"
.PARAMETER Role
Search for a role by the Role name. For example, "System"
.INPUTS
None. You can't redirect or pipe input to this function.
.OUTPUTS
This function outputs a PSCustomObject with the Name of the principal and the UUID.
.EXAMPLE
C:\PS> Search-PlatformDirectory -User "person@domain.com"
Searches all reachable tenant directories (AD, Federated, etc.) to find a person@domain.com and if successful, return the
tenant's UUID for this user.
.EXAMPLE
C:\PS> Search-PlatformDirectory -Group "WidgetAdmins@domain.com"
Searches all reachable tenant directories (AD, Federated, etc.) to find the group WidgetAdmins@domain.com and if successful,
return the tenant's UUID for this group.
#>
param
(
[Parameter(Mandatory = $true, HelpMessage = "Specify the User to find from DirectoryServices.",ParameterSetName = "User")]
[System.Object]$User,
[Parameter(Mandatory = $true, HelpMessage = "Specify the Group to find from DirectoryServices.",ParameterSetName = "Group")]
[System.Object]$Group,
[Parameter(Mandatory = $true, HelpMessage = "Specify the Role to find from DirectoryServices.",ParameterSetName = "Role")]
[System.Object]$Role
)
# verifying an active platform connection
Verify-PlatformConnection
# building the query from parameter set
Switch ($PSCmdlet.ParameterSetName)
{
"User" { $query = ("SELECT InternalName AS ID,SystemName AS Name FROM DSUsers WHERE SystemName LIKE '%{0}%'" -f $User); break }
"Role" { $query = ("SELECT ID,Name FROM Role WHERE Name LIKE '%{0}%'" -f ($Role -replace "'","''")); break }
"Group" { $query = ("SELECT InternalName AS ID,SystemName AS Name FROM DSGroups WHERE SystemName LIKE '%{0}%'" -f $Group); break }
}
Write-Verbose ("SQLQuery: [{0}]" -f $query)
# make the query
$sqlquery = Query-VaultRedRock -SqlQuery $query
# new ArrayList to hold multiple entries
$principals = New-Object System.Collections.ArrayList
# if the query isn't null
if ($sqlquery -ne $null)
{
# for each secret in the query
foreach ($principal in $sqlquery)
{
# Counter for the principal objects
$p++; Write-Progress -Activity "Processing Principals into Objects" -Status ("{0} out of {1} Complete" -f $p,$sqlquery.Count) -PercentComplete ($p/($sqlquery | Measure-Object | Select-Object -ExpandProperty Count)*100)
# creating the PlatformPrincipal object
$obj = [PlatformPrincipal]::new($principal.Name, $principal.ID)
$principals.Add($obj) | Out-Null
}# foreach ($principal in $sqlquery)
}# if ($sqlquery -ne $null)
return $principals
}# function global:Search-PlatformDirectory
#endregion
###########
###########
#region ### global:Get-PlatformPrincipal # Searches existing directories for principals or roles and returns the Name and ID by exact searches
###########
function global:Get-PlatformPrincipal
{
<#
.SYNOPSIS
This function will retrieve the UUID of the specified principal from all reachable tenant directories by exact match.
.DESCRIPTION
This function will retrieve the UUID of the specified principal from all reachable tenant directories by exact match. This
function will only principals that exactly match by name of what is searched, no partial searches.
.PARAMETER User
Search for a user by their User Principal Name. For example, "person@domain.com"
.PARAMETER Group
Search for a group by their Group and domain. For example, "WidgetAdmins@domain.com"
.PARAMETER Role
Search for a role by the Role name. For example, "System"
.INPUTS
None. You can't redirect or pipe input to this function.
.OUTPUTS
This function outputs a PSCustomObject with the requested data.
.EXAMPLE
C:\PS> Get-PlatformPrincipal -User "person@domain.com"
Searches all reachable tenant directories (AD, Federated, etc.) to find a person@domain.com and if successful, return the
tenant's UUID for this user.
.EXAMPLE
C:\PS> Get-PlatformPrincipal -Group "WidgetAdmins@domain.com"
Searches all reachable tenant directories (AD, Federated, etc.) to find the group WidgetAdmins@domain.com and if successful,
return the tenant's UUID for this group.
#>
param
(
[Parameter(Mandatory = $true, HelpMessage = "Specify the User to find from DirectoryServices.",ParameterSetName = "User")]
[System.Object]$User,
[Parameter(Mandatory = $true, HelpMessage = "Specify the Group to find from DirectoryServices.",ParameterSetName = "Group")]
[System.Object]$Group,
[Parameter(Mandatory = $true, HelpMessage = "Specify the Role to find from DirectoryServices.",ParameterSetName = "Role")]
[System.Object]$Role
)
# verifying an active platform connection
Verify-PlatformConnection
# building the query from parameter set
Switch ($PSCmdlet.ParameterSetName)
{
"User" { $query = ("SELECT InternalName AS ID,SystemName AS Name FROM DSUsers WHERE SystemName = '{0}'" -f $User); break }
"Role" { $query = ("SELECT ID,Name FROM Role WHERE Name = '{0}'" -f ($Role -replace "'","''")); break }
"Group" { $query = ("SELECT InternalName AS ID,SystemName AS Name FROM DSGroups WHERE SystemName LIKE '%{0}%'" -f $Group); break }
}
Write-Verbose ("SQLQuery: [{0}]" -f $query)
# make the query
$sqlquery = Query-VaultRedRock -SqlQuery $query
# new ArrayList to hold multiple entries
$principals = New-Object System.Collections.ArrayList
# if the query isn't null
if ($sqlquery -ne $null)
{
# for each secret in the query
foreach ($principal in $sqlquery)
{
# Counter for the principal objects
$p++; Write-Progress -Activity "Processing Principals into Objects" -Status ("{0} out of {1} Complete" -f $p,$sqlquery.Count) -PercentComplete ($p/($sqlquery | Measure-Object | Select-Object -ExpandProperty Count)*100)
# creating the PlatformPrincipal object
$obj = [PlatformPrincipal]::new($principal.Name, $principal.ID)
$principals.Add($obj) | Out-Null
}# foreach ($principal in $sqlquery)
}# if ($sqlquery -ne $null)
return $principals
}# function global:Get-PlatformPrincipal
#endregion
###########
###########
#region ### global:Get-PlatformSecret # Gets a PlatformSecret object from the tenant
###########
function global:Get-PlatformSecret
{
<#
.SYNOPSIS
Gets a Secret object from the Delinea Platform.
.DESCRIPTION
Gets a Secret object from the Delinea Platform. This returns a PlatformSecret class object containing properties about
the Secret object, and methods to potentially retreive the Secret contents as well. By default, Get-PlatformSecret without
any parameters will get all Secret objects in the Platform.
The additional methods are the following:
.RetrieveSecret()
- For Text Secrets, this will retreive the contents of the Text Secret and store it in the SecretText property.
- For File Secrets, this will prepare the File Download URL to be used with the .ExportSecret() method.
.ExportSecret()
- For Text Secrets, this will export the contents of the SecretText property as a text file into the ParentPath directory.
- For File Secrets, this will download the file from the Platform into the ParentPath directory.
If the directory or file does not exist during ExportSecret(), the directory and file will be created. If the file
already exists, then the file will be renamed and appended with a random 8 character string to avoid file name conflicts.
.PARAMETER Name
Get a Platform Secret by it's Secret Name.
.PARAMETER Uuid
Get a Platform Secret by it's UUID.
.PARAMETER Type
Get a Platform Secret by it's Type, either File or Text.
.PARAMETER Limit
Limits the number of potential Secret objects returned.
.INPUTS
None. You can't redirect or pipe input to this function.
.OUTPUTS
This function outputs a PlatformSecret class object.
.EXAMPLE
C:\PS> Get-PlatformSecret
Gets all Secret objects from the Delinea Platform.
.EXAMPLE
C:\PS> Get-PlatformSecret -Limit 10
Gets 10 Secret objects from the Delinea Platform.
.EXAMPLE
C:\PS> Get-PlatformSecret -Name "License Keys"
Gets all Secret objects with the Secret Name "License Keys".
.EXAMPLE
C:\PS> Get-PlatformSecret -Type File
Gets all File Secret objects.
.EXAMPLE
C:\PS> Get-PlatformSecret -Uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
Get a Secret object with the specified UUID.
#>
[CmdletBinding(DefaultParameterSetName="All")]
param
(
[Parameter(Mandatory = $true, HelpMessage = "The name of the secret to search.",ParameterSetName = "Name")]
[System.String]$Name,
[Parameter(Mandatory = $true, HelpMessage = "The Uuid of the secret to search.",ParameterSetName = "Uuid")]
[System.String]$Uuid,
[Parameter(Mandatory = $true, HelpMessage = "The type of the secret to search.",ParameterSetName = "Type")]
[ValidateSet("Text","File")]
[System.String]$Type,
[Parameter(Mandatory = $false, HelpMessage = "Limits the number of results.")]
[System.Int32]$Limit
)
# verifying an active platform connection
Verify-PlatformConnection
# base query
$query = "SELECT * FROM DataVault"
# if the All set was not used
if ($PSCmdlet.ParameterSetName -ne "All")
{
# arraylist for extra options
$extras = New-Object System.Collections.ArrayList
# appending the WHERE
$query += " WHERE "
# setting up the extra conditionals
if ($PSBoundParameters.ContainsKey("Name")) { $extras.Add(("SecretName = '{0}'" -f $Name)) | Out-Null }
if ($PSBoundParameters.ContainsKey("Uuid")) { $extras.Add(("ID = '{0}'" -f $Uuid)) | Out-Null }
if ($PSBoundParameters.ContainsKey("Type")) { $extras.ADD(("Type = '{0}'" -f $Type)) | Out-Null }
# join them together with " AND " and append it to the query
$query += ($extras -join " AND ")
}# if ($PSCmdlet.ParameterSetName -ne "All")
# if Limit was used, append it to the query
if ($PSBoundParameters.ContainsKey("Limit")) { $query += (" LIMIT {0}" -f $Limit) }
Write-Verbose ("SQLQuery: [{0}]" -f $query)
# make the query
$sqlquery = Query-VaultRedRock -SqlQuery $query
# new ArrayList to hold multiple entries
$secrets = New-Object System.Collections.ArrayList
# if the query isn't null
if ($sqlquery -ne $null)
{
# for each secret in the query
foreach ($secret in $sqlquery)
{
if ($secret -eq $null) { continue }
# Counter for the secret objects
$p++; Write-Progress -Activity "Processing Secrets into Objects" -Status ("{0} out of {1} Complete" -f $p,$sqlquery.Count) -PercentComplete ($p/($sqlquery | Measure-Object | Select-Object -ExpandProperty Count)*100)
# creating the PlatformSecret object
$obj = [PlatformSecret]::new($secret)
$secrets.Add($obj) | Out-Null
}# foreach ($secret in $query)
}# if ($sqlquery -ne $null)
# returning the secrets
return $secrets
}# lobal:Get-PlatformSecret
#endregion
###########
###########
#region ### global:Get-PlatformSet # Gets a Platform Set object
###########
function global:Get-PlatformSet
{
<#
.SYNOPSIS
Gets a Set object from the Delinea Platform.
.DESCRIPTION
Gets a Set object from the Delinea Platform. This returns a PlatformSet class object containing properties about
the Set object. By default, Get-PlatformSet without any parameters will get all Set objects in the Platform.
.PARAMETER Type
Gets only Sets of this type. Currently only "System","Database","Account", or "Secret" is supported.
.PARAMETER Name
Gets only Sets with this name.
.PARAMETER Uuid
Gets only Sets with this UUID.
.PARAMETER Limit
Limits the number of potential Set objects returned.
.INPUTS
None. You can't redirect or pipe input to this function.
.OUTPUTS
This function outputs a PlatformSet class object.
.EXAMPLE
C:\PS> Get-PlatformSet
Gets all Set objects from the Delinea Platform.
.EXAMPLE
C:\PS> Get-PlatformSet -Limit 10
Gets 10 Set objects from the Delinea Platform.
.EXAMPLE
C:\PS> Get-PlatformSet -Name "Widget Systems"
Gets all Secret objects with the Set Name "Widget Systems".
.EXAMPLE
C:\PS> Get-PlatformSet -Type "Account"
Get all Account Sets from the Delinea Platform.
.EXAMPLE
C:\PS> Get-PlatformSecret -Uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
Get a Secret object with the specified UUID.
#>
[CmdletBinding(DefaultParameterSetName="All")]
param
(
[Parameter(Mandatory = $true, HelpMessage = "The type of Set to search.", ParameterSetName = "Type")]
[ValidateSet("System","Database","Account","Secret")]
[System.String]$Type,
[Parameter(Mandatory = $true, HelpMessage = "The name of the Set to search.", ParameterSetName = "Name")]
[Parameter(Mandatory = $false, HelpMessage = "The name of the Set to search.", ParameterSetName = "Type")]
[System.String]$Name,
[Parameter(Mandatory = $true, HelpMessage = "The Uuid of the Set to search.",ParameterSetName = "Uuid")]
[Parameter(Mandatory = $false, HelpMessage = "The name of the Set to search.", ParameterSetName = "Type")]
[System.String]$Uuid,
[Parameter(Mandatory = $false, HelpMessage = "Limits the number of results.")]
[System.Int32]$Limit
)
# verifying an active platform connection
Verify-PlatformConnection
# setting the base query
$query = "Select * FROM Sets"
# arraylist for extra options
$extras = New-Object System.Collections.ArrayList
# if the All set was not used
if ($PSCmdlet.ParameterSetName -ne "All")
{
# placeholder to translate type names
[System.String] $newtype = $null
# switch to translate backend naming convention
Switch ($Type)
{
"System" { $newtype = "Server" ; break }
"Database" { $newtype = "VaultDatabase" ; break }
"Account" { $newtype = "VaultAccount" ; break }
"Secret" { $newtype = "DataVault" ; break }
default { }
}# Switch ($Type)
# appending the WHERE
$query += " WHERE "
# setting up the extra conditionals
if ($PSBoundParameters.ContainsKey("Type")) { $extras.Add(("ObjectType = '{0}'" -f $newtype)) | Out-Null }
if ($PSBoundParameters.ContainsKey("Name")) { $extras.Add(("Name = '{0}'" -f $Name)) | Out-Null }
if ($PSBoundParameters.ContainsKey("Uuid")) { $extras.Add(("ID = '{0}'" -f $Uuid)) | Out-Null }
# join them together with " AND " and append it to the query
$query += ($extras -join " AND ")
}# if ($PSCmdlet.ParameterSetName -ne "All")
# if Limit was used, append it to the query
if ($PSBoundParameters.ContainsKey("Limit")) { $query += (" LIMIT {0}" -f $Limit) }
Write-Verbose ("SQLQuery: [{0}]" -f $query)
# making the query
$sqlquery = Query-VaultRedRock -SQLQuery $query
# ArrayList to hold objects
$queries = New-Object System.Collections.ArrayList
# if the query isn't null
if ($sqlquery -ne $null)
{
foreach ($q in $sqlquery)
{
# Counter for the secret objects
$p++; Write-Progress -Activity "Processing Sets into Objects" -Status ("{0} out of {1} Complete" -f $p,$sqlquery.Count) -PercentComplete ($p/($sqlquery | Measure-Object | Select-Object -ExpandProperty Count)*100)
Write-Verbose ("Working with [{0}] Set [{1}]" -f $q.Name, $q.ObjectType)
# create a new Platform Set object
$set = [PlatformSet]::new($q)
# if the Set is a Manual Set or a Folder (not a Dynamic Set)
if ($set.SetType -eq "ManualBucket" -or $set.SetType -eq "Phantom")
{
# get the Uuids of the members
$set.GetMembers()
}
# determin the potential owner of the Set
$set.determineOwner()
$queries.Add($set) | Out-Null
}# foreach ($q in $query)
}# if ($query -ne $null)
else
{
return $false
}
#return $set
return $queries
}# function global:Get-PlatformSet
#endregion
###########
###########
#region ### global:Get-PlatformAccount # Gets a Platform Account object
###########
function global:Get-PlatformAccount
{
<#
.SYNOPSIS
Gets an Account object from the Delinea Platform.
.DESCRIPTION
Gets an Account object from the Delinea Platform. This returns a PlatformAccount class object containing properties about
the Account object. By default, Get-PlatformAccount without any parameters will get all Account objects in the Platform.
In addition, the PlatformAccount class also contains methods to help interact with that Account.
The additional methods are the following:
.CheckInPassword()
- Checks in a password that has been checked out by the CheckOutPassword() method.
.CheckOutPassword()
- Checks out the password to this Account.
.ManageAccount()
- Sets this Account to be managed by the Platform.
.UnmanageAccount()
- Sets this Account to be un-managed by the Platform.
.UpdatePassword([System.String]$newpassword)
- Updates the password to this Account.
.VerifyPassword()
- Verifies if this password on this Account is correct.
.PARAMETER Type
Gets only Accounts of this type. Currently only "Local","Domain","Database", or "Cloud" is supported.
.PARAMETER SourceName
Gets only Accounts with the name of the Parent object that hosts this account. For local accounts, this would
be the hostname of the system the account exists on. For domain accounts, this is the name of the domain.
.PARAMETER UserName
Gets only Accounts with this as the username.
.PARAMETER Uuid
Gets only Accounts with this UUID.
.PARAMETER Limit
Limits the number of potential Account objects returned.
.INPUTS
None. You can't redirect or pipe input to this function.
.OUTPUTS
This function outputs a PlatformAccount class object.
.EXAMPLE
C:\PS> Get-PlatformAccount
Gets all Account objects from the Delinea Platform.
.EXAMPLE
C:\PS> Get-PlatformAccount -Limit 10
Gets 10 Account objects from the Delinea Platform.
.EXAMPLE
C:\PS> Get-PlatformAccount -Type Domain
Get all domain-based Accounts.
.EXAMPLE
C:\PS> Get-PlatformAccount -Username "root"
Gets all Account objects with the username, "root".
.EXAMPLE
C:\PS> Get-PlatformAccount -SourceName "LINUXSERVER01.DOMAIN.COM"
Get all Account objects who's source (parent) object is LINUXSERVER01.DOMAIN.COM.
.EXAMPLE
C:\PS> Get-PlatformAccount -Uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
Get an Account object with the specified UUID.
#>
[CmdletBinding(DefaultParameterSetName="All")]
param
(
[Parameter(Mandatory = $false, HelpMessage = "The type of Account to search.", ParameterSetName = "Type")]
[ValidateSet("Local","Domain","Database","Cloud")]
[System.String]$Type,
[Parameter(Mandatory = $false, HelpMessage = "The name of the Source of the Account to search.", ParameterSetName = "Source")]
[System.String]$SourceName,
[Parameter(Mandatory = $false, HelpMessage = "The name of the Account to search.", ParameterSetName = "UserName")]
[System.String]$UserName,
[Parameter(Mandatory = $false, HelpMessage = "The Uuid of the Account to search.",ParameterSetName = "Uuid")]
[System.String]$Uuid,
[Parameter(Mandatory = $false, HelpMessage = "A limit on number of objects to query.")]
[System.Int32]$Limit
)
# verifying an active platform connection
Verify-PlatformConnection
# setting the base query
$query = "Select * FROM VaultAccount"
# arraylist for extra options
$extras = New-Object System.Collections.ArrayList
# if the All set was not used
if ($PSCmdlet.ParameterSetName -ne "All")
{
# appending the WHERE
$query += " WHERE "
# setting up the extra conditionals
if ($PSBoundParameters.ContainsKey("Type"))
{
Switch ($Type)
{
"Cloud" { $extras.Add("CloudProviderID IS NOT NULL") | Out-Null ; break }
"Domain" { $extras.Add("DomainID IS NOT NULL") | Out-Null ; break }
"Database" { $extras.Add("DatabaseID IS NOT NULL") | Out-Null ; break }
"Local" { $extras.Add("Host IS NOT NULL") | Out-Null ; break }
}
}# if ($PSBoundParameters.ContainsKey("Type"))
if ($PSBoundParameters.ContainsKey("SourceName")) { $extras.Add(("Name = '{0}'" -f $SourceName)) | Out-Null }
if ($PSBoundParameters.ContainsKey("UserName")) { $extras.Add(("User = '{0}'" -f $UserName)) | Out-Null }
if ($PSBoundParameters.ContainsKey("Uuid")) { $extras.Add(("ID = '{0}'" -f $Uuid)) | Out-Null }
# join them together with " AND " and append it to the query
$query += ($extras -join " AND ")
}# if ($PSCmdlet.ParameterSetName -ne "All")
# if Limit was used, append it to the query
if ($PSBoundParameters.ContainsKey("Limit")) { $query += (" LIMIT {0}" -f $Limit) }
Write-Verbose ("SQLQuery: [{0}]" -f $query)
# making the query
$sqlquery = Query-VaultRedRock -SQLQuery $query
# ArrayList to hold objects
$queries = New-Object System.Collections.ArrayList
# if the query isn't null
if ($sqlquery -ne $null)
{
foreach ($q in $sqlquery)
{
# Counter for the secret objects
$p++; Write-Progress -Activity "Processing Accounts into Objects" -Status ("{0} out of {1} Complete" -f $p,$sqlquery.Count) -PercentComplete ($p/($sqlquery | Measure-Object | Select-Object -ExpandProperty Count)*100)
Write-Verbose ("Working with Account [{0}\{1}]" -f $q.Name, $q.User)
# minor placeholder to hold account type in case of all call
[System.String]$accounttype = $null
if ($q.CloudProviderID -ne $null) { $accounttype = "Cloud" }
if ($q.DomainID -ne $null) { $accounttype = "Domain" }
if ($q.DatabaseID -ne $null) { $accounttype = "Database" }
if ($q.Host -ne $null) { $accounttype = "Local" }
# create a new Platform Account object
$account = [PlatformAccount]::new($q, $accounttype)
$queries.Add($account) | Out-Null
}# foreach ($q in $query)
}# if ($query -ne $null)
else
{
return $false
}
#return $queries
return $queries
}# function global:Get-PlatformAccount
#endregion
###########
###########
#region ### global:Verify-PlatformCredentials # Verifies the password is health for the specified account
###########
function global:Verify-PlatformCredentials
{
<#
.SYNOPSIS
Verifies an Account object's password as known by the Platform.
.DESCRIPTION
This function will verify if the specified account's password, as it is known by the Platform is correct.
This will cause the Platform to reach out to the Account's parent object in an attempt to validate the password.
Will return $true if it is correct, or $false if it is incorrect or cannot validate for any reason.
.PARAMETER Uuid
The Uuid of the Account to validate.
.EXAMPLE
C:\PS> Verify-PlatformCredentials -Uuid "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
Verifies the password of the Account with the spcified Uuid.
#>
param
(
[Parameter(Mandatory = $true, HelpMessage = "The Uuid of the Account to check.",ParameterSetName = "Uuid")]
[System.String]$Uuid
)
# verifying an active platform connection
Verify-PlatformConnection
$response = Invoke-PlatformAPI -APICall ServerManage/CheckAccountHealth -Body (@{ ID = $Uuid } | ConvertTo-Json)
if ($response -eq "OK")
{
[System.Boolean]$responseAnswer = $true
}
else
{
[System.Boolean]$responseAnswer = $false
}
return $responseAnswer
}# function global:Verify-PlatformCredentials
#endregion
###########
###########
#region ### global:Get-PlatformVault # Gets a Platform Vault object
###########
function global:Get-PlatformVault
{
<#
.SYNOPSIS
Gets a Vault object from the Delinea Platform.
.DESCRIPTION
Gets a Vault object from the Delinea Platform. This returns a PlatformVault class object containing properties about
the Vault object. By default, Get-PlatformVault without any parameters will get all Vault objects in the Platform.
.PARAMETER Type
Gets only Vaults of this type. Currently only "SecretServer" is supported.