Merge pull request #87 from PetriAsi/get-all-for-every-get

Get all items for every get-command
This commit is contained in:
Petri Asikainen 2021-05-15 18:54:58 +03:00 committed by GitHub
commit f2db33fa59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 416 additions and 47 deletions

View file

@ -1,3 +1,35 @@
<#
.SYNOPSIS
# Gets a list of Snipe-it Accessories
.PARAMETER search
A text string to search the Accessory data
.PARAMETER id
A id of specific Accessory
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE
Get-Accessory -url "https://assets.example.com" -token "token..."
.EXAMPLE
Get-Accessory -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "HP" }
#>
function Get-Accessory() {
Param(
[string]$search,
@ -19,6 +51,8 @@ function Get-Accessory() {
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
@ -35,10 +69,26 @@ function Get-Accessory() {
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-Accessory @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -14,9 +14,6 @@ Specify exact asset tag to query
.PARAMETER asset_serial
Specify exact asset serial to query
.PARAMETER all
A return all results , works with -search and other filters
.PARAMETER order_number
Optionally restrict asset results to this order number
@ -48,11 +45,14 @@ Specify the column name you wish to sort by
Specify the order (asc or desc) you wish to order by on your sort column
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50.
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -81,8 +81,6 @@ function Get-Asset() {
[string]$asset_serial,
[bool]$all = $false,
[int]$order_number,
[int]$model_id,
@ -112,6 +110,7 @@ function Get-Asset() {
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,

View file

@ -15,11 +15,14 @@ Specify the column name you wish to sort by
Specify the order (asc or desc) you wish to order by on your sort column
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50.
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -48,6 +51,8 @@ function Get-AssetMaintenance() {
[int]$limit = 50,
[switch]$all = $false,
[int]$offset,
[parameter(mandatory = $true)]
@ -66,10 +71,26 @@ function Get-AssetMaintenance() {
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-AssetMaintenance @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -8,6 +8,15 @@ A text string to search the Categories data
.PARAMETER id
A id of specific Category
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Category()
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
@ -62,7 +73,23 @@ function Get-Category()
GetParameters = $SearchParameter
}
$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-Category @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -8,6 +8,15 @@ A text string to search the Companies data
.PARAMETER id
A id of specific Company
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Company()
[int]$offset,
[switch]$all = $false,
[parameter(mandatory=$true)]
[string]$url,
@ -62,7 +73,23 @@ function Get-Company()
GetParameters = $SearchParameter
}
$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-Company @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -8,6 +8,15 @@ A text string to search the Components data
.PARAMETER id
A id of specific Component
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -44,6 +53,8 @@ function Get-Component() {
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
@ -70,7 +81,23 @@ function Get-Component() {
GetParameters = $SearchParameter
}
$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-Component @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -29,6 +29,7 @@ function Get-CustomField()
Token = $apiKey
}
$result = Invoke-SnipeitMethod @Parameters
$result

View file

@ -8,6 +8,15 @@ A text string to search the Departments data
.PARAMETER id
A id of specific Department
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Department()
[int]$offset,
[switch]$all = $false,
[ValidateSet('id', 'name', 'image', 'users_count', 'created_at')]
[string]$sort = "created_at",
@ -65,8 +76,24 @@ function Get-Department()
GetParameters = $SearchParameter
}
$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-Department @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -8,6 +8,16 @@ A text string to search the Licenses data
.PARAMETER id
A id of specific License
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -60,6 +70,8 @@ function Get-License() {
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
@ -86,8 +98,24 @@ function Get-License() {
GetParameters = $SearchParameter
}
$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-License @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -8,6 +8,15 @@ A text string to search the Manufactures data
.PARAMETER id
A id of specific Manufactuter
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Manufacturer()
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
@ -62,7 +73,23 @@ function Get-Manufacturer()
GetParameters = $SearchParameter
}
$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-Manufacturer @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -8,6 +8,15 @@ A text string to search the Models data
.PARAMETER id
A id of specific model
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -15,10 +24,10 @@ URL of Snipeit system, can be set using Set-Info command
Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE
Get-Models -url "https://assets.example.com" -token "token..."
Get-Model -url "https://assets.example.com" -token "token..."
.EXAMPLE
Get-Models -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "DL380" }
Get-Model -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "DL380" }
#>
@ -36,6 +45,8 @@ function Get-Model()
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
@ -59,10 +70,26 @@ function Get-Model()
Uri = $apiurl
Method = 'Get'
Token = $apiKey
#GetParameters = $SearchParameter
GetParameters = $SearchParameter
}
$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-Model @callargs
$res
if ($res.count -ne $limit ) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -8,6 +8,15 @@ A text string to search the Locations data
.PARAMETER id
A id of specific Location
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-SnipeitLocation()
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
@ -62,8 +73,24 @@ function Get-SnipeitLocation()
GetParameters = $SearchParameter
}
$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-SnipeitLocation @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -8,6 +8,15 @@ A text string to search the Status Labels data
.PARAMETER id
A id of specific Status Label
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Status()
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
@ -62,7 +73,23 @@ function Get-Status()
GetParameters = $SearchParameter
}
$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-Status @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -8,6 +8,15 @@ A text string to search the Supliers data
.PARAMETER id
A id of specific Suplier
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Supplier()
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
@ -62,8 +73,24 @@ function Get-Supplier()
GetParameters = $SearchParameter
}
$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-Supplier @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}

View file

@ -8,6 +8,15 @@ A text string to search the User data
.PARAMETER id
A id of specific User
.PARAMETER limit
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
.PARAMETER offset
Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
@ -42,6 +51,8 @@ function Get-User() {
[int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)]
[string]$url,
@ -67,7 +78,23 @@ function Get-User() {
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-User @callargs
$res
if ($res.count -lt $limit) {
break
}
$offstart = $offstart + $limit
}
} else {
$result = Invoke-SnipeitMethod @Parameters
$result
}
}