@@ -14,6 +14,12 @@ Exact asset tag to query
1414. PARAMETER asset_serial
1515Exact asset serialnumber to query
1616
17+ . PARAMETER audit_due
18+ Retrieve a list of assets that are due for auditing soon.
19+
20+ . PARAMETER audit_overdue
21+ Retrieve a list of assets that are overdue for auditing.
22+
1723. PARAMETER order_number
1824Optionally restrict asset results to this order number
1925
@@ -73,6 +79,7 @@ Get-SnipeitAsset -asset_tag "myAssetTag"-url "https://assets.example.com"-token
7379#>
7480
7581function Get-SnipeitAsset () {
82+ [CmdletBinding (DefaultParameterSetName = ' Search' )]
7683 Param (
7784 [parameter (ParameterSetName = ' Search' )]
7885 [string ]$search ,
@@ -87,6 +94,12 @@ function Get-SnipeitAsset() {
8794 [Alias (' asset_serial' )]
8895 [string ]$serial ,
8996
97+ [parameter (ParameterSetName = ' Assets due auditing soon' )]
98+ [switch ]$audit_due ,
99+
100+ [parameter (ParameterSetName = ' Assets overdue for auditing' )]
101+ [switch ]$audit_overdue ,
102+
90103 [parameter (ParameterSetName = ' Search' )]
91104 [string ]$order_number ,
92105
@@ -118,57 +131,52 @@ function Get-SnipeitAsset() {
118131 [int ]$status_id ,
119132
120133 [parameter (ParameterSetName = ' Search' )]
121- [string ]$sort = " created_at" ,
134+ [parameter (ParameterSetName = ' Assets due auditing soon' )]
135+ [parameter (ParameterSetName = ' Assets overdue for auditing' )]
136+ [ValidateSet (' id' , ' created_at' , ' asset_tag' , ' serial' , ' order_number' , ' model_id' , ' category_id' , ' manufacturer_id' , ' company_id' , ' location_id' , ' status' , ' status_id' )]
137+ [string ]$sort ,
122138
123139 [parameter (ParameterSetName = ' Search' )]
140+ [parameter (ParameterSetName = ' Assets due auditing soon' )]
141+ [parameter (ParameterSetName = ' Assets overdue for auditing' )]
124142 [ValidateSet (" asc" , " desc" )]
125- [string ]$order = " desc " ,
143+ [string ]$order ,
126144
127145 [parameter (ParameterSetName = ' Search' )]
146+ [parameter (ParameterSetName = ' Assets due auditing soon' )]
147+ [parameter (ParameterSetName = ' Assets overdue for auditing' )]
128148 [int ]$limit = 50 ,
129149
130150 [parameter (ParameterSetName = ' Search' )]
151+ [parameter (ParameterSetName = ' Assets due auditing soon' )]
152+ [parameter (ParameterSetName = ' Assets overdue for auditing' )]
131153 [int ]$offset ,
132154
133155 [parameter (ParameterSetName = ' Search' )]
156+ [parameter (ParameterSetName = ' Assets due auditing soon' )]
157+ [parameter (ParameterSetName = ' Assets overdue for auditing' )]
134158 [switch ]$all = $false ,
159+
135160 [parameter (mandatory = $true )]
136161 [string ]$url ,
137162
138163 [parameter (mandatory = $true )]
139164 [string ]$apiKey
140165 )
166+
141167 Test-SnipeitAlias - invocationName $MyInvocation.InvocationName - commandName $MyInvocation.MyCommand.Name
142168
143169 $SearchParameter = . Get-ParameterValue - Parameters $MyInvocation.MyCommand.Parameters - BoundParameters $PSBoundParameters
144170
145-
146- $apiurl = " $url /api/v1/hardware"
147-
148- if ($search -and ($asset_tag -or $asset_serial -or $id )) {
149- Throw " [$ ( $MyInvocation.MyCommand.Name ) ] Please specify only one of -search , -asset_tag or -asset_serial parameter"
150- }
151-
152- if ($id ) {
153- if ( $search -or $asset_serial -or $asset_tag ) {
154- Throw " [$ ( $MyInvocation.MyCommand.Name ) ] Please specify only one of -search , -asset_tag or -asset_serial parameter"
155- }
156- $apiurl = " $url /api/v1/hardware/$id "
171+ switch ($PsCmdlet.ParameterSetName ) {
172+ ' Search' { $apiurl = " $url /api/v1/hardware" }
173+ ' Get with id' {$apiurl = " $url /api/v1/hardware/$id " }
174+ ' Get with asset tag' {$apiurl = " $url /api/v1/hardware/bytag/$asset_tag " }
175+ ' Get with serial' { $apiurl = " $url /api/v1/hardware/byserial/$asset_serial " }
176+ ' Assets due auditing soon' {$apiurl = " $url /api/v1/hardware/audit/due" }
177+ ' Assets overdue for auditing' {$apiurl = " $url /api/v1/hardware/audit/overdue" }
157178 }
158179
159- if ($asset_tag ) {
160- if ( $search -or $asset_serial -or $id ) {
161- Throw " [$ ( $MyInvocation.MyCommand.Name ) ] Please specify only one of -search , -asset_tag or -asset_serial parameter"
162- }
163- $apiurl = " $url /api/v1/hardware/bytag/$asset_tag "
164- }
165-
166- if ($asset_serial ) {
167- if ( $search -or $asset_tag ) {
168- Throw " [$ ( $MyInvocation.MyCommand.Name ) ] Please specify only one of-search , -asset_tag or -asset_serial parameter"
169- }
170- $apiurl = " $url /api/v1/hardware/byserial/$asset_serial "
171- }
172180
173181 $Parameters = @ {
174182 Uri = $apiurl
@@ -180,6 +188,7 @@ function Get-SnipeitAsset() {
180188 if ($all ) {
181189 $offstart = $ (if ($offset ){$offset } Else {0 })
182190 $callargs = $SearchParameter
191+ Write-Verbose " Callargs: $ ( $callargs | convertto-json ) "
183192 $callargs.Remove (' all' )
184193
185194 while ($true ) {
0 commit comments