-all option for get-asset, returns all results

This commit is contained in:
Petri Asikainen 2021-01-18 11:06:10 +02:00
parent a09eb8c23e
commit 1b12288920

View file

@ -14,6 +14,9 @@ Specify exact asset tag to query
.PARAMETER asset_serial .PARAMETER asset_serial
Specify exact asset serial to query Specify exact asset serial to query
.PARAMETER all
A return all results , works with -search and other filters
.PARAMETER order_number .PARAMETER order_number
Optionally restrict asset results to this order number Optionally restrict asset results to this order number
@ -57,16 +60,16 @@ URL of Snipeit system, can be set using Set-Info command
Users API Key for Snipeit, can be set using Set-Info command Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE .EXAMPLE
Get-Asset -url "https://assets.example.com" -token "token..." Get-Asset -url "https://assets.example.com"-token "token..."
.EXAMPLE .EXAMPLE
Get-Asset -search "myMachine" -url "https://assets.example.com" -token "token..." Get-Asset -search "myMachine"-url "https://assets.example.com"-token "token..."
.EXAMPLE .EXAMPLE
Get-Asset -search "myMachine" -url "https://assets.example.com" -token "token..." Get-Asset -search "myMachine"-url "https://assets.example.com"-token "token..."
.EXAMPLE .EXAMPLE
Get-Asset -asset_tag "myAssetTag" -url "https://assets.example.com" -token "token..." Get-Asset -asset_tag "myAssetTag"-url "https://assets.example.com"-token "token..."
#> #>
function Get-Asset() { function Get-Asset() {
Param( Param(
@ -78,6 +81,8 @@ function Get-Asset() {
[string]$asset_serial, [string]$asset_serial,
[bool]$all = $false,
[int]$order_number, [int]$order_number,
[int]$model_id, [int]$model_id,
@ -119,26 +124,26 @@ function Get-Asset() {
$apiurl = "$url/api/v1/hardware" $apiurl = "$url/api/v1/hardware"
if ($search -and ($asset_tag -or $asset_serial -or $id)) { if($search -and ($asset_tag -or $asset_serial -or $id)) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter" Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter"
} }
if ($id) { if($id) {
if ( $search -or $asset_serial -or $asset_tag) { if( $search -or $asset_serial -or $asset_tag) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter" Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter"
} }
$apiurl= "$url/api/v1/hardware/$id" $apiurl= "$url/api/v1/hardware/$id"
} }
if ($asset_tag) { if($asset_tag) {
if ( $search -or $asset_serial -or $id) { if( $search -or $asset_serial -or $id) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter" Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter"
} }
$apiurl= "$url/api/v1/hardware/bytag/$asset_tag" $apiurl= "$url/api/v1/hardware/bytag/$asset_tag"
} }
if ($asset_serial) { if($asset_serial) {
if ( $search -or $asset_tag) { if( $search -or $asset_tag) {
Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of-search , -asset_tag or -asset_serial parameter" Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of-search , -asset_tag or -asset_serial parameter"
} }
$apiurl= "$url/api/v1/hardware/byserial/$asset_serial" $apiurl= "$url/api/v1/hardware/byserial/$asset_serial"
@ -151,9 +156,27 @@ function Get-Asset() {
Token = $apiKey Token = $apiKey
} }
$result = Invoke-SnipeitMethod @Parameters if($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
while($true) {
$callargs['offset'] = $offstart
$callargs['limit'] = $limit
$res=Get-Asset @callargs
$res
if( $res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
$result
} }