diff --git a/SnipeitPS/Public/Get-Accessory.ps1 b/SnipeitPS/Public/Get-Accessory.ps1 index d820eea..9703b6d 100644 --- a/SnipeitPS/Public/Get-Accessory.ps1 +++ b/SnipeitPS/Public/Get-Accessory.ps1 @@ -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,9 +69,25 @@ function Get-Accessory() { 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 + } } diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index b5335ae..59edc73 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -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, @@ -124,26 +123,26 @@ function Get-Asset() { $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" } - if($id) { - if( $search -or $asset_serial -or $asset_tag) { + if ($id) { + if ( $search -or $asset_serial -or $asset_tag) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter" } $apiurl= "$url/api/v1/hardware/$id" } - if($asset_tag) { - if( $search -or $asset_serial -or $id) { + if ($asset_tag) { + if ( $search -or $asset_serial -or $id) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter" } $apiurl= "$url/api/v1/hardware/bytag/$asset_tag" } - if($asset_serial) { - if( $search -or $asset_tag) { + if ($asset_serial) { + if ( $search -or $asset_tag) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of-search , -asset_tag or -asset_serial parameter" } $apiurl= "$url/api/v1/hardware/byserial/$asset_serial" @@ -156,17 +155,17 @@ function Get-Asset() { Token = $apiKey } - if($all) { - $offstart = $(if($offset){$offset} Else {0}) + if ($all) { + $offstart = $(if ($offset){$offset} Else {0}) $callargs = $SearchParameter $callargs.Remove('all') - while($true) { + while ($true) { $callargs['offset'] = $offstart $callargs['limit'] = $limit $res=Get-Asset @callargs $res - if( $res.count -lt $limit) { + if ( $res.count -lt $limit) { break } $offstart = $offstart + $limit diff --git a/SnipeitPS/Public/Get-AssetMaintenance.ps1 b/SnipeitPS/Public/Get-AssetMaintenance.ps1 index 4828474..8aa17a6 100644 --- a/SnipeitPS/Public/Get-AssetMaintenance.ps1 +++ b/SnipeitPS/Public/Get-AssetMaintenance.ps1 @@ -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,9 +71,25 @@ function Get-AssetMaintenance() { 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 + } } diff --git a/SnipeitPS/Public/Get-Category.ps1 b/SnipeitPS/Public/Get-Category.ps1 index 21e1ad2..0457a23 100644 --- a/SnipeitPS/Public/Get-Category.ps1 +++ b/SnipeitPS/Public/Get-Category.ps1 @@ -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') - $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 + } } diff --git a/SnipeitPS/Public/Get-Company.ps1 b/SnipeitPS/Public/Get-Company.ps1 index 04134b4..c02088a 100644 --- a/SnipeitPS/Public/Get-Company.ps1 +++ b/SnipeitPS/Public/Get-Company.ps1 @@ -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') - $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 + } } diff --git a/SnipeitPS/Public/Get-Component.ps1 b/SnipeitPS/Public/Get-Component.ps1 index 961930e..e601a02 100644 --- a/SnipeitPS/Public/Get-Component.ps1 +++ b/SnipeitPS/Public/Get-Component.ps1 @@ -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') - $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 + } } diff --git a/SnipeitPS/Public/Get-CustomField.ps1 b/SnipeitPS/Public/Get-CustomField.ps1 index 8a26143..6a65368 100644 --- a/SnipeitPS/Public/Get-CustomField.ps1 +++ b/SnipeitPS/Public/Get-CustomField.ps1 @@ -29,6 +29,7 @@ function Get-CustomField() Token = $apiKey } + $result = Invoke-SnipeitMethod @Parameters $result diff --git a/SnipeitPS/Public/Get-Department.ps1 b/SnipeitPS/Public/Get-Department.ps1 index 8164a6d..ef37e6c 100644 --- a/SnipeitPS/Public/Get-Department.ps1 +++ b/SnipeitPS/Public/Get-Department.ps1 @@ -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') - $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 + } } diff --git a/SnipeitPS/Public/Get-License.ps1 b/SnipeitPS/Public/Get-License.ps1 index f87e2cb..e6f9da2 100644 --- a/SnipeitPS/Public/Get-License.ps1 +++ b/SnipeitPS/Public/Get-License.ps1 @@ -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') - $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 + } } diff --git a/SnipeitPS/Public/Get-Manufacturer.ps1 b/SnipeitPS/Public/Get-Manufacturer.ps1 index c22d1f9..f225070 100644 --- a/SnipeitPS/Public/Get-Manufacturer.ps1 +++ b/SnipeitPS/Public/Get-Manufacturer.ps1 @@ -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') - $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 + } } diff --git a/SnipeitPS/Public/Get-Model.ps1 b/SnipeitPS/Public/Get-Model.ps1 index 57eded7..f766230 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -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, @@ -62,7 +73,23 @@ function Get-Model() #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 + } } diff --git a/SnipeitPS/Public/Get-SnipeitLocation.ps1 b/SnipeitPS/Public/Get-SnipeitLocation.ps1 index 18f8e4c..5b60c0d 100644 --- a/SnipeitPS/Public/Get-SnipeitLocation.ps1 +++ b/SnipeitPS/Public/Get-SnipeitLocation.ps1 @@ -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') - $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 + } } diff --git a/SnipeitPS/Public/Get-Status.ps1 b/SnipeitPS/Public/Get-Status.ps1 index 816c8b1..8e65108 100644 --- a/SnipeitPS/Public/Get-Status.ps1 +++ b/SnipeitPS/Public/Get-Status.ps1 @@ -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') - $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 + } } diff --git a/SnipeitPS/Public/Get-Supplier.ps1 b/SnipeitPS/Public/Get-Supplier.ps1 index a92481f..311641c 100644 --- a/SnipeitPS/Public/Get-Supplier.ps1 +++ b/SnipeitPS/Public/Get-Supplier.ps1 @@ -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') - $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 + } } diff --git a/SnipeitPS/Public/Get-User.ps1 b/SnipeitPS/Public/Get-User.ps1 index c9b8858..3cb99b1 100644 --- a/SnipeitPS/Public/Get-User.ps1 +++ b/SnipeitPS/Public/Get-User.ps1 @@ -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') - $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 + } }