-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFind-HXBulkAcquisition.ps1
81 lines (65 loc) · 3.58 KB
/
Find-HXBulkAcquisition.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
function Find-HXBulkAcquisition {
[CmdletBinding()]
[OutputType([psobject])]
param(
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[string] $Uri,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession] $WebSession,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[string] $Search,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[string] $Offset,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[string] $Limit,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[string] $Sort,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[string] $Filter,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[Alias("hostset_id")]
[string] $HostSetId,
[Parameter(Mandatory=$false, ValueFromPipelineByPropertyName=$true)]
[string] $HostSet
)
begin { }
process {
# Uri filtering:
if ($Uri -match '\d$') { $Endpoint = $Uri+'/hx/api/v3/acqs/bulk/?' }
elseif ($Uri -match '\d/$') { $Endpoint = $Uri+'hx/api/v3/acqs/bulk?' }
else { $Endpoint = $Uri + "/?" }
# Header:
$headers = @{ "Accept" = "application/json" }
# Enable auto-search by a given host-set id:
if (($HostsetId) -and (-not($Search))) { $Search = $HostsetId }
if ($Search) { $Endpoint = $Endpoint + "&search=" + $Search }
if ($Offset) { $Endpoint = $Endpoint + "&offset=" + $Offset }
if ($Limit) { $Endpoint = $Endpoint + "&limit=" + $Limit }
if ($Sort) { $Endpoint = $Endpoint + "&sort=" + $Sort }
if ($Filter) { $Endpoint = $Endpoint + "&" + $Filter }
# Request:
$WebRequest = Invoke-WebRequest -Uri $Endpoint -WebSession $WebSession -Method Get -Headers $headers -SkipCertificateCheck
$WebRequestContent = $WebRequest.Content | ConvertFrom-Json
# Return the object:
$WebRequestContent.data.entries | Foreach-Object {
$out = New-Object System.Object
$out | Add-Member -Type NoteProperty -Name bulkacquisition_id -Value $_._id
if ($Hostset) { $out | Add-Member -Type NoteProperty -Name hostset -Value $Hostset }
$out | Add-Member -Type NoteProperty -Name revision -Value $_._revision
$out | Add-Member -Type NoteProperty -Name comment -Value $_.comment
$out | Add-Member -Type NoteProperty -Name create_actor_id -Value $_.create_actor._id
$out | Add-Member -Type NoteProperty -Name create_actor_username -Value $_.create_actor.username
$out | Add-Member -Type NoteProperty -Name create_time -Value $_.create_time
$out | Add-Member -Type NoteProperty -Name update_actor_id -Value $_.update_actor._id
$out | Add-Member -Type NoteProperty -Name update_actor_username -Value $_.update_actor.username
$out | Add-Member -Type NoteProperty -Name update_time -Value $_.update_time
$out | Add-Member -Type NoteProperty -Name state -Value $_.state
$out | Add-Member -Type NoteProperty -Name endpoint -Value $_.url
$out | Add-Member -Type NoteProperty -Name running_state -Value $_.stats.running_state
$out | Add-Member -Type NoteProperty -Name Uri -Value $Uri
$out | Add-Member -Type NoteProperty -Name WebSession -Value $WebSession
$out
}
}
end { }
}