-all parameter for all suported get-commands

This commit is contained in:
Petri Asikainen 2021-01-19 08:02:00 +02:00
parent 1b12288920
commit 8ae7ff7622
15 changed files with 415 additions and 46 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() { function Get-Accessory() {
Param( Param(
[string]$search, [string]$search,
@ -19,6 +51,8 @@ function Get-Accessory() {
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -35,9 +69,25 @@ function Get-Accessory() {
Token = $apiKey Token = $apiKey
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .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
@ -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 Specify the order (asc or desc) you wish to order by on your sort column
.PARAMETER limit .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 .PARAMETER offset
Offset to use Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -81,8 +81,6 @@ function Get-Asset() {
[string]$asset_serial, [string]$asset_serial,
[bool]$all = $false,
[int]$order_number, [int]$order_number,
[int]$model_id, [int]$model_id,
@ -112,6 +110,7 @@ function Get-Asset() {
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -124,26 +123,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"
@ -156,17 +155,17 @@ function Get-Asset() {
Token = $apiKey Token = $apiKey
} }
if($all) { if ($all) {
$offstart = $(if($offset){$offset} Else {0}) $offstart = $(if ($offset){$offset} Else {0})
$callargs = $SearchParameter $callargs = $SearchParameter
$callargs.Remove('all') $callargs.Remove('all')
while($true) { while ($true) {
$callargs['offset'] = $offstart $callargs['offset'] = $offstart
$callargs['limit'] = $limit $callargs['limit'] = $limit
$res=Get-Asset @callargs $res=Get-Asset @callargs
$res $res
if( $res.count -lt $limit) { if ( $res.count -lt $limit) {
break break
} }
$offstart = $offstart + $limit $offstart = $offstart + $limit

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 Specify the order (asc or desc) you wish to order by on your sort column
.PARAMETER limit .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 .PARAMETER offset
Offset to use Offset to use
.PARAMETER all
A return all results, works with -offset and other parameters
.PARAMETER url .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -48,6 +51,8 @@ function Get-AssetMaintenance() {
[int]$limit = 50, [int]$limit = 50,
[switch]$all = $false,
[int]$offset, [int]$offset,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
@ -66,9 +71,25 @@ function Get-AssetMaintenance() {
Token = $apiKey Token = $apiKey
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .PARAMETER id
A id of specific Category 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Category()
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -62,7 +73,23 @@ function Get-Category()
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .PARAMETER id
A id of specific Company 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Company()
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory=$true)] [parameter(mandatory=$true)]
[string]$url, [string]$url,
@ -62,7 +73,23 @@ function Get-Company()
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .PARAMETER id
A id of specific Component 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -44,6 +53,8 @@ function Get-Component() {
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -70,7 +81,23 @@ function Get-Component() {
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 Token = $apiKey
} }
$result = Invoke-SnipeitMethod @Parameters $result = Invoke-SnipeitMethod @Parameters
$result $result

View file

@ -8,6 +8,15 @@ A text string to search the Departments data
.PARAMETER id .PARAMETER id
A id of specific Department 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Department()
[int]$offset, [int]$offset,
[switch]$all = $false,
[ValidateSet('id', 'name', 'image', 'users_count', 'created_at')] [ValidateSet('id', 'name', 'image', 'users_count', 'created_at')]
[string]$sort = "created_at", [string]$sort = "created_at",
@ -65,8 +76,24 @@ function Get-Department()
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .PARAMETER id
A id of specific License 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -60,6 +70,8 @@ function Get-License() {
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -86,8 +98,24 @@ function Get-License() {
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .PARAMETER id
A id of specific Manufactuter 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Manufacturer()
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -62,7 +73,23 @@ function Get-Manufacturer()
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .PARAMETER id
A id of specific model 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command 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 Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE .EXAMPLE
Get-Models -url "https://assets.example.com" -token "token..." Get-Model -url "https://assets.example.com" -token "token..."
.EXAMPLE .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, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -62,7 +73,23 @@ function Get-Model()
#GetParameters = $SearchParameter #GetParameters = $SearchParameter
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .PARAMETER id
A id of specific Location 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-SnipeitLocation()
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -62,8 +73,24 @@ function Get-SnipeitLocation()
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .PARAMETER id
A id of specific Status Label 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Status()
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -62,7 +73,23 @@ function Get-Status()
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .PARAMETER id
A id of specific Suplier 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -36,6 +45,8 @@ function Get-Supplier()
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -62,8 +73,24 @@ function Get-Supplier()
GetParameters = $SearchParameter GetParameters = $SearchParameter
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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 .PARAMETER id
A id of specific User 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 .PARAMETER url
URL of Snipeit system, can be set using Set-Info command URL of Snipeit system, can be set using Set-Info command
@ -42,6 +51,8 @@ function Get-User() {
[int]$offset, [int]$offset,
[switch]$all = $false,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -67,7 +78,23 @@ function Get-User() {
Token = $apiKey Token = $apiKey
} }
$result = Invoke-SnipeitMethod @Parameters if ($all) {
$offstart = $(if($offset){$offset} Else {0})
$callargs = $SearchParameter
$callargs.Remove('all')
$result 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
}
} }