forked from pspete/psPAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find-PASSafe.ps1
60 lines (38 loc) · 1.25 KB
/
Find-PASSafe.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
# .ExternalHelp psPAS-help.xml
function Find-PASSafe {
[CmdletBinding()]
param(
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $false
)]
[string]$search,
[parameter(
Mandatory = $false,
ValueFromPipelineByPropertyName = $false
)]
[int]$TimeoutSec
)
BEGIN {
Assert-VersionRequirement -RequiredVersion 10.1 -MaximumVersion 11.7
#Create base URL for request
$URI = "$Script:BaseURI/api/Safes"
$SearchQuery = $null
$Limit = 25 #default if you call the API with no value
}#begin
PROCESS {
If ( -Not [string]::IsNullOrEmpty($search) ) {
$SearchQuery = "&$($PSBoundParameters | Get-PASParameter | ConvertTo-QueryString)"
}
$InitialResponse = Invoke-PASRestMethod -Uri "$URI`?limit=$Limit$SearchQuery" -Method GET -WebSession $Script:WebSession -TimeoutSec $TimeoutSec
$Total = $InitialResponse.Total
If ($Total -gt 0) {
$Safes = [Collections.Generic.List[Object]]::New(($InitialResponse.Safes))
For ( $Offset = $Limit ; $Offset -lt $Total ; $Offset += $Limit ) {
$Null = $Safes.AddRange((Invoke-PASRestMethod -Uri "$URI`?limit=$Limit&OffSet=$Offset$searchQuery" -Method GET -WebSession $Script:WebSession -TimeoutSec $TimeoutSec).Safes)
}
$Safes
}
}#process
END { }#end
}