From 4385d8709361076831e5f463b6291c1ac4bb4d03 Mon Sep 17 00:00:00 2001 From: Tim Murphy Date: Mon, 29 Jun 2020 18:50:43 -0500 Subject: [PATCH 01/34] Added New-Category Function --- SnipeitPS/Public/New-Category.ps1 | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 SnipeitPS/Public/New-Category.ps1 diff --git a/SnipeitPS/Public/New-Category.ps1 b/SnipeitPS/Public/New-Category.ps1 new file mode 100644 index 0000000..56c40e7 --- /dev/null +++ b/SnipeitPS/Public/New-Category.ps1 @@ -0,0 +1,78 @@ +<# +.SYNOPSIS +# Create a new Snipe-IT Category +.PARAMETER name +Name of new category to be created +.PARAMETER type +Type of new category to be created (asset, accessory, consumable, component) +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command +.PARAMETER apiKey +User's API Key for Snipeit, can be set using Set-Info command +.PARAMETER use_default_eula +If switch is present, use the primary default EULA +.PARAMETER require_acceptance +If switch is present, require users to confirm acceptance of assets in this category +.PARAMETER checkin_email +If switch is present, send email to user on checkin/checkout +.EXAMPLE +New-Category -name "Laptops" -category_type "asset" -url "Snipe-IT URL here..." -apiKey "API key here..." +#> + +function New-Category() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [string]$name, + + [parameter(mandatory = $true)] + [string]$category_type, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey, + + [switch]$use_default_eula, + + [switch]$require_acceptance, + + [switch]$checkin_email + ) + + $Values = . Get-ParameterValue + + if ($use_default_eula) { + $Values += @("use_default_eula" = "true") + } + + if ($require_acceptance) { + $Values += @("require_acceptance" = "true") + } + + if ($checkin_email) { + $Values += @("checkin_email" = "true") + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/categories" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} From bb53a87cf4fd17211956385e755fe7f9f1b2ec74 Mon Sep 17 00:00:00 2001 From: Tim Murphy Date: Mon, 29 Jun 2020 19:09:45 -0500 Subject: [PATCH 02/34] Added New-Category Function --- SnipeitPS/SnipeItPS.psd1 | Bin 9596 -> 9646 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 780aa3c855eff24d20b6fc42db8090c49bb5cdd0..abc0c3dc75995b75949ee6d32b3cac2a05f0ab20 100644 GIT binary patch delta 20 ccmez4wa$CPA<@b2gfu3<5#`!^NOTuJ0Bn^Ba{vGU delta 12 UcmZ4I{l{y=A<@lWM0fE604zKPOaK4? From ea0461970689b69cb1d24e9ae03a6e213216eae3 Mon Sep 17 00:00:00 2001 From: Tim Murphy Date: Mon, 29 Jun 2020 19:18:49 -0500 Subject: [PATCH 03/34] Fixed brackets --- SnipeitPS/Public/New-Category.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SnipeitPS/Public/New-Category.ps1 b/SnipeitPS/Public/New-Category.ps1 index 56c40e7..aefbd53 100644 --- a/SnipeitPS/Public/New-Category.ps1 +++ b/SnipeitPS/Public/New-Category.ps1 @@ -49,15 +49,15 @@ function New-Category() $Values = . Get-ParameterValue if ($use_default_eula) { - $Values += @("use_default_eula" = "true") + $Values += @{"use_default_eula" = "true"} } if ($require_acceptance) { - $Values += @("require_acceptance" = "true") + $Values += @{"require_acceptance" = "true"} } if ($checkin_email) { - $Values += @("checkin_email" = "true") + $Values += @{"checkin_email" = "true"} } $Body = $Values | ConvertTo-Json; From 54b7b4db3b6f09ce0fc0a8f5fa1c24d3d4a737c0 Mon Sep 17 00:00:00 2001 From: Tim Murphy Date: Mon, 29 Jun 2020 19:27:04 -0500 Subject: [PATCH 04/34] Added parameter validation for category_type --- SnipeitPS/Public/New-Category.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/SnipeitPS/Public/New-Category.ps1 b/SnipeitPS/Public/New-Category.ps1 index aefbd53..e047ff6 100644 --- a/SnipeitPS/Public/New-Category.ps1 +++ b/SnipeitPS/Public/New-Category.ps1 @@ -31,6 +31,7 @@ function New-Category() [string]$name, [parameter(mandatory = $true)] + [ValidateSet("asset", "accessory", "consumable", "component")] [string]$category_type, [parameter(mandatory = $true)] From 95eed3330c5b8f6683f74d4c7f0341321207034a Mon Sep 17 00:00:00 2001 From: Tim Murphy Date: Mon, 29 Jun 2020 19:42:05 -0500 Subject: [PATCH 05/34] Added license as valid category_type --- SnipeitPS/Public/New-Category.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SnipeitPS/Public/New-Category.ps1 b/SnipeitPS/Public/New-Category.ps1 index e047ff6..f83d33b 100644 --- a/SnipeitPS/Public/New-Category.ps1 +++ b/SnipeitPS/Public/New-Category.ps1 @@ -4,7 +4,7 @@ .PARAMETER name Name of new category to be created .PARAMETER type -Type of new category to be created (asset, accessory, consumable, component) +Type of new category to be created (asset, accessory, consumable, component, license) .PARAMETER url URL of Snipeit system, can be set using Set-Info command .PARAMETER apiKey @@ -31,7 +31,7 @@ function New-Category() [string]$name, [parameter(mandatory = $true)] - [ValidateSet("asset", "accessory", "consumable", "component")] + [ValidateSet("asset", "accessory", "consumable", "component", "license")] [string]$category_type, [parameter(mandatory = $true)] From b3826d33eccdedae366e510bb4a2d5aee524ef93 Mon Sep 17 00:00:00 2001 From: Tim Murphy Date: Mon, 29 Jun 2020 20:24:56 -0500 Subject: [PATCH 06/34] Changed to hash table, fixed optional switches formatting --- SnipeitPS/Public/New-Category.ps1 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/SnipeitPS/Public/New-Category.ps1 b/SnipeitPS/Public/New-Category.ps1 index f83d33b..d7e8e04 100644 --- a/SnipeitPS/Public/New-Category.ps1 +++ b/SnipeitPS/Public/New-Category.ps1 @@ -47,20 +47,24 @@ function New-Category() [switch]$checkin_email ) - $Values = . Get-ParameterValue - + # $Values = . Get-ParameterValue + $Values = @{ + "name" = $name + "category_type" = $category_type + } + if ($use_default_eula) { - $Values += @{"use_default_eula" = "true"} + $Values += @{"use_default_eula" = $true} } if ($require_acceptance) { - $Values += @{"require_acceptance" = "true"} + $Values += @{"require_acceptance" = $true} } if ($checkin_email) { - $Values += @{"checkin_email" = "true"} + $Values += @{"checkin_email" = $true} } - + $Body = $Values | ConvertTo-Json; $Parameters = @{ From af62a28bef2975aa843fe38ea84ece7c90cde36f Mon Sep 17 00:00:00 2001 From: Tim Murphy Date: Mon, 29 Jun 2020 20:26:45 -0500 Subject: [PATCH 07/34] Removed unnecessary comment --- SnipeitPS/Public/New-Category.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SnipeitPS/Public/New-Category.ps1 b/SnipeitPS/Public/New-Category.ps1 index d7e8e04..b0b54b2 100644 --- a/SnipeitPS/Public/New-Category.ps1 +++ b/SnipeitPS/Public/New-Category.ps1 @@ -47,12 +47,11 @@ function New-Category() [switch]$checkin_email ) - # $Values = . Get-ParameterValue $Values = @{ "name" = $name "category_type" = $category_type } - + if ($use_default_eula) { $Values += @{"use_default_eula" = $true} } From 13fa97f36fc594e7d85a2abc2d116c8d01e8275a Mon Sep 17 00:00:00 2001 From: Tim Murphy Date: Mon, 29 Jun 2020 20:29:49 -0500 Subject: [PATCH 08/34] Updated Example --- SnipeitPS/Public/New-Category.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SnipeitPS/Public/New-Category.ps1 b/SnipeitPS/Public/New-Category.ps1 index b0b54b2..c750a14 100644 --- a/SnipeitPS/Public/New-Category.ps1 +++ b/SnipeitPS/Public/New-Category.ps1 @@ -16,7 +16,7 @@ If switch is present, require users to confirm acceptance of assets in this cate .PARAMETER checkin_email If switch is present, send email to user on checkin/checkout .EXAMPLE -New-Category -name "Laptops" -category_type "asset" -url "Snipe-IT URL here..." -apiKey "API key here..." +New-Category -name "Laptops" -category_type asset -url "Snipe-IT URL here..." -apiKey "API key here..." #> function New-Category() From fe5e3c6ba2bd7ac4029348e0b4ebcec5e93d94e9 Mon Sep 17 00:00:00 2001 From: Harry John Date: Thu, 3 Sep 2020 01:41:32 +0100 Subject: [PATCH 09/34] Added Remove-AssetMaintenance Function --- SnipeitPS/Public/Remove-AssetMaintenance.ps1 | 52 +++++++++++++++++++ SnipeitPS/SnipeItPS.psd1 | Bin 9596 -> 9668 bytes 2 files changed, 52 insertions(+) create mode 100644 SnipeitPS/Public/Remove-AssetMaintenance.ps1 diff --git a/SnipeitPS/Public/Remove-AssetMaintenance.ps1 b/SnipeitPS/Public/Remove-AssetMaintenance.ps1 new file mode 100644 index 0000000..338bbe7 --- /dev/null +++ b/SnipeitPS/Public/Remove-AssetMaintenance.ps1 @@ -0,0 +1,52 @@ +function Remove-AssetMaintenance { + <# + .SYNOPSIS + Remove asset maintenance from Snipe-it asset system + .DESCRIPTION + Removes asset maintenance event from Snipe-it asset system by ID + .PARAMETER ID + Unique ID of the asset maintenance to be removed + .EXAMPLE + Remove-AssetMaintenance -ID 44 -url $url -apiKey $secret -Verbose + #> + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + param ( + # Asset maintenance ID + [Parameter(Mandatory = $true)] + [string] + $ID, + + # SnipeIt URL + [Parameter(Mandatory = $true)] + [string] + $url, + + # SnipeIt ApiKey + [Parameter(Mandatory = $true)] + [string] + $apiKey + ) + + $Values = @{ + "ID" = $ID + } + + $Body = $Values | ConvertTo-Json + + $Parameters = @{ + Uri = "$url/api/v1/maintenances/$ID" + Method = 'Delete' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 780aa3c855eff24d20b6fc42db8090c49bb5cdd0..527c112a77d8afa8de1d056534d5e043d956f612 100644 GIT binary patch delta 32 ocmez4b;NsvnB?Sj5)#}&45 Date: Thu, 3 Sep 2020 02:44:17 +0100 Subject: [PATCH 10/34] Added Remove-Asset to FunctionsToExport Resolves #63 --- SnipeitPS/SnipeItPS.psd1 | Bin 9596 -> 9646 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 780aa3c855eff24d20b6fc42db8090c49bb5cdd0..8a183bdc71f103f4967a289f3e6072befdcd7a7b 100644 GIT binary patch delta 40 tcmez4wa$BknB?Sj5)$G;45 delta 12 TcmZ4I{l{yAnB-;;$uu4SBvAyV From 1c31e67419ffdc44c5227e6a59a04378caacab46 Mon Sep 17 00:00:00 2001 From: gvoynov <72854456+gvoynov@users.noreply.github.com> Date: Mon, 14 Dec 2020 11:53:02 +0200 Subject: [PATCH 11/34] Create Remove-User Would you consider adding function for deleting users from snipe-it? --- SnipeitPS/Public/Remove-User | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 SnipeitPS/Public/Remove-User diff --git a/SnipeitPS/Public/Remove-User b/SnipeitPS/Public/Remove-User new file mode 100644 index 0000000..69148c2 --- /dev/null +++ b/SnipeitPS/Public/Remove-User @@ -0,0 +1,48 @@ +<# + .SYNOPSIS + Removes User from Snipe-it asset system + .DESCRIPTION + Long description + .PARAMETER ID + Unique ID For User to be removed + .EXAMPLE + Remove-User -ID 44 -url $url -apiKey $secret -Verbose +#> + +function Remove-User () +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [string]$ID, + [parameter(mandatory = $true)] + [string]$URL, + [parameter(mandatory = $true)] + [string]$APIKey + + ) + + $Values = @{ + "ID" = $ID + } + + $Body = $Values | ConvertTo-Json + + $Parameters = @{ + Uri = "$url/api/v1/users/$ID" + Method = 'Delete' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} From 1b1228892018f2d774d07edb5d92a3ea231fa13b Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Mon, 18 Jan 2021 11:06:10 +0200 Subject: [PATCH 12/34] -all option for get-asset, returns all results --- SnipeitPS/Public/Get-Asset.ps1 | 57 ++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 97f9d1f..b5335ae 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -14,6 +14,9 @@ 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 @@ -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 .EXAMPLE -Get-Asset -url "https://assets.example.com" -token "token..." +Get-Asset -url "https://assets.example.com"-token "token..." .EXAMPLE -Get-Asset -search "myMachine" -url "https://assets.example.com" -token "token..." +Get-Asset -search "myMachine"-url "https://assets.example.com"-token "token..." .EXAMPLE -Get-Asset -search "myMachine" -url "https://assets.example.com" -token "token..." +Get-Asset -search "myMachine"-url "https://assets.example.com"-token "token..." .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() { Param( @@ -78,6 +81,8 @@ function Get-Asset() { [string]$asset_serial, + [bool]$all = $false, + [int]$order_number, [int]$model_id, @@ -119,31 +124,31 @@ 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" + $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" + $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" + $apiurl= "$url/api/v1/hardware/byserial/$asset_serial" } - + $Parameters = @{ Uri = $apiurl Method = 'Get' @@ -151,9 +156,27 @@ function Get-Asset() { 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-Asset @callargs + $res + if( $res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + + } From 8ae7ff76224babbbd17a532510eef9cd97bf1dea Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Tue, 19 Jan 2021 08:02:00 +0200 Subject: [PATCH 13/34] -all parameter for all suported get-commands --- SnipeitPS/Public/Get-Accessory.ps1 | 54 ++++++++++++++++++++++- SnipeitPS/Public/Get-Asset.ps1 | 33 +++++++------- SnipeitPS/Public/Get-AssetMaintenance.ps1 | 27 ++++++++++-- SnipeitPS/Public/Get-Category.ps1 | 31 ++++++++++++- SnipeitPS/Public/Get-Company.ps1 | 31 ++++++++++++- SnipeitPS/Public/Get-Component.ps1 | 31 ++++++++++++- SnipeitPS/Public/Get-CustomField.ps1 | 1 + SnipeitPS/Public/Get-Department.ps1 | 31 ++++++++++++- SnipeitPS/Public/Get-License.ps1 | 32 +++++++++++++- SnipeitPS/Public/Get-Manufacturer.ps1 | 31 ++++++++++++- SnipeitPS/Public/Get-Model.ps1 | 35 +++++++++++++-- SnipeitPS/Public/Get-SnipeitLocation.ps1 | 31 ++++++++++++- SnipeitPS/Public/Get-Status.ps1 | 31 ++++++++++++- SnipeitPS/Public/Get-Supplier.ps1 | 31 ++++++++++++- SnipeitPS/Public/Get-User.ps1 | 31 ++++++++++++- 15 files changed, 415 insertions(+), 46 deletions(-) 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 + } } From fdf52ce2e44343b145633a5b8fe58459e683909f Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Tue, 19 Jan 2021 11:51:08 +0200 Subject: [PATCH 14/34] Where did this # came from?" --- SnipeitPS/Public/Get-Model.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SnipeitPS/Public/Get-Model.ps1 b/SnipeitPS/Public/Get-Model.ps1 index f766230..d003bbc 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -70,7 +70,7 @@ function Get-Model() Uri = $apiurl Method = 'Get' Token = $apiKey - #GetParameters = $SearchParameter + GetParameters = $SearchParameter } if ($all) { From 35a4ab68fee2e42f4722e9fb76008d39643cc04c Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Tue, 19 Jan 2021 12:39:53 +0200 Subject: [PATCH 15/34] Don't require status_id or model_id when updating asset --- SnipeitPS/Public/Set-Asset.ps1 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/SnipeitPS/Public/Set-Asset.ps1 b/SnipeitPS/Public/Set-Asset.ps1 index fd11788..7c38f78 100644 --- a/SnipeitPS/Public/Set-Asset.ps1 +++ b/SnipeitPS/Public/Set-Asset.ps1 @@ -59,12 +59,14 @@ function Set-Asset() [hashtable] $customfields ) - $Values = @{ - "name" = $Name - "status_id" = $status_id - "model_id" = $model_id - } + $Values = @{} + if ($Name) { $Values.Add('name',$Name)} + + if ($status_id) { $Values.Add('status_id',$status_id)} + + if ($model_id) { $Values.Add('model_id',$model_id)} + if ($customfields) { $Values += $customfields From e559e711436a77244aabcaf0c9a3b2551f2b1e31 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Tue, 19 Jan 2021 17:34:41 +0200 Subject: [PATCH 16/34] Export Reset-AssetOwner --- SnipeitPS/SnipeItPS.psd1 | Bin 9660 -> 9718 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 1a5873b62e142b0e6221911f91864a4c4d0a2bb4..a719c3ba5025bdfbbf8aab716455491501491bc4 100644 GIT binary patch delta 30 mcmdnv{mpyB2Jy+y#7!n|5Z7Z3Vn}5up1e}rcC(bkB3=N=O$%QD delta 23 fcmez7y~lgQ2Jy*H#Pudga!lSJZn8N Date: Sun, 24 Jan 2021 09:27:16 +0200 Subject: [PATCH 17/34] Match case with module directory --- SnipeitPS/{SnipeItPS.psd1 => SnipeitPS.psd1} | Bin SnipeitPS/{SnipeItPS.psm1 => SnipeitPS.psm1} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename SnipeitPS/{SnipeItPS.psd1 => SnipeitPS.psd1} (100%) rename SnipeitPS/{SnipeItPS.psm1 => SnipeitPS.psm1} (100%) diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeitPS.psd1 similarity index 100% rename from SnipeitPS/SnipeItPS.psd1 rename to SnipeitPS/SnipeitPS.psd1 diff --git a/SnipeitPS/SnipeItPS.psm1 b/SnipeitPS/SnipeitPS.psm1 similarity index 100% rename from SnipeitPS/SnipeItPS.psm1 rename to SnipeitPS/SnipeitPS.psm1 From a5e691d8f058c04dbfd51ea9cb63d1601fc829e7 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 24 Jan 2021 09:30:47 +0200 Subject: [PATCH 18/34] Module name case --- SnipeitPS/{SnipeitPS.psd1 => SnipeItPS.psd1} | Bin SnipeitPS/{SnipeitPS.psm1 => SnipeItPS.psm1} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename SnipeitPS/{SnipeitPS.psd1 => SnipeItPS.psd1} (100%) rename SnipeitPS/{SnipeitPS.psm1 => SnipeItPS.psm1} (100%) diff --git a/SnipeitPS/SnipeitPS.psd1 b/SnipeitPS/SnipeItPS.psd1 similarity index 100% rename from SnipeitPS/SnipeitPS.psd1 rename to SnipeitPS/SnipeItPS.psd1 diff --git a/SnipeitPS/SnipeitPS.psm1 b/SnipeitPS/SnipeItPS.psm1 similarity index 100% rename from SnipeitPS/SnipeitPS.psm1 rename to SnipeitPS/SnipeItPS.psm1 From 6828244dfa31f2e2308582e9a88ea06fd72eb348 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Fri, 29 Jan 2021 18:08:19 +0200 Subject: [PATCH 19/34] #67 --- SnipeitPS/Private/Get-ParameterValue.ps1 | 19 +++++++------------ SnipeitPS/Public/Get-Accessory.ps1 | 2 +- SnipeitPS/Public/Get-Asset.ps1 | 2 +- SnipeitPS/Public/Get-AssetMaintenance.ps1 | 2 +- SnipeitPS/Public/Get-Category.ps1 | 2 +- SnipeitPS/Public/Get-Company.ps1 | 2 +- SnipeitPS/Public/Get-Component.ps1 | 2 +- SnipeitPS/Public/Get-Department.ps1 | 2 +- SnipeitPS/Public/Get-License.ps1 | 2 +- SnipeitPS/Public/Get-Manufacturer.ps1 | 2 +- SnipeitPS/Public/Get-Model.ps1 | 2 +- SnipeitPS/Public/Get-SnipeitLocation.ps1 | 2 +- SnipeitPS/Public/Get-Status.ps1 | 2 +- SnipeitPS/Public/Get-Supplier.ps1 | 2 +- SnipeitPS/Public/Get-User.ps1 | 2 +- SnipeitPS/Public/New-Accessory.ps1 | 2 +- SnipeitPS/Public/New-AssetMaintenance.ps1 | 2 +- SnipeitPS/Public/New-Company.ps1 | 2 +- SnipeitPS/Public/New-Component.ps1 | 2 +- SnipeitPS/Public/New-CustomField.ps1 | 2 +- SnipeitPS/Public/New-Department.ps1 | 2 +- SnipeitPS/Public/New-License.ps1 | 2 +- SnipeitPS/Public/New-Location.ps1 | 2 +- SnipeitPS/Public/Set-Accessory.ps1 | 2 +- SnipeitPS/Public/Set-License.ps1 | 2 +- SnipeitPS/Public/Set-Model.ps1 | 2 +- SnipeitPS/Public/Set-SnipeitLocation.ps1 | 2 +- 27 files changed, 33 insertions(+), 38 deletions(-) diff --git a/SnipeitPS/Private/Get-ParameterValue.ps1 b/SnipeitPS/Private/Get-ParameterValue.ps1 index f8f7882..2cbb971 100644 --- a/SnipeitPS/Private/Get-ParameterValue.ps1 +++ b/SnipeitPS/Private/Get-ParameterValue.ps1 @@ -21,23 +21,21 @@ function Get-ParameterValue { # } [CmdletBinding()] param( - # The $MyInvocation for the caller -- DO NOT pass this (dot-source Get-ParameterValues instead) - $Invocation = $MyInvocation, - # The $PSBoundParameters for the caller -- DO NOT pass this (dot-source Get-ParameterValues instead) - $BoundParameters = $PSBoundParameters, + # Pass $MyInvocation.MyCommand.Parameters to function, powershell 7 seems to only populate variables with dot sourcing + [parameter(mandatory = $true)] + $Parameters + , [string[]]$DefaultExcludeParameter = @("id", "url", "apiKey", 'Debug', 'Verbose') ) if ($MyInvocation.Line[($MyInvocation.OffsetInLine - 1)] -ne '.') { - throw "Get-ParameterValues must be dot-sourced, like this: . Get-ParameterValues" - } - if ($PSBoundParameters.Count -gt 0) { - throw "You should not pass parameters to Get-ParameterValues, just dot-source it like this: . Get-ParameterValues" + throw "Get-ParameterValue must be dot-sourced, like this: . Get-ParameterValues" } + $ParameterValues = @{} - foreach ($parameter in $Invocation.MyCommand.Parameters.GetEnumerator()) { + foreach ($parameter in $Parameters.GetEnumerator()) { # gm -in $parameter.Value | Out-Default try { $key = $parameter.Key @@ -48,9 +46,6 @@ function Get-ParameterValue { } } - if ($BoundParameters.ContainsKey($key)) { - $ParameterValues[$key] = $BoundParameters[$key] - } } } finally {} diff --git a/SnipeitPS/Public/Get-Accessory.ps1 b/SnipeitPS/Public/Get-Accessory.ps1 index 9703b6d..1f9a639 100644 --- a/SnipeitPS/Public/Get-Accessory.ps1 +++ b/SnipeitPS/Public/Get-Accessory.ps1 @@ -60,7 +60,7 @@ function Get-Accessory() { [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $Parameters = @{ Uri = "$url/api/v1/accessories" diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 59edc73..f6dc4d2 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -118,7 +118,7 @@ function Get-Asset() { [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/hardware" diff --git a/SnipeitPS/Public/Get-AssetMaintenance.ps1 b/SnipeitPS/Public/Get-AssetMaintenance.ps1 index 8aa17a6..1cb2108 100644 --- a/SnipeitPS/Public/Get-AssetMaintenance.ps1 +++ b/SnipeitPS/Public/Get-AssetMaintenance.ps1 @@ -62,7 +62,7 @@ function Get-AssetMaintenance() { [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $Parameters = @{ Uri = "$url/api/v1/maintenances" diff --git a/SnipeitPS/Public/Get-Category.ps1 b/SnipeitPS/Public/Get-Category.ps1 index 0457a23..bee35c8 100644 --- a/SnipeitPS/Public/Get-Category.ps1 +++ b/SnipeitPS/Public/Get-Category.ps1 @@ -54,7 +54,7 @@ function Get-Category() [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/categories" diff --git a/SnipeitPS/Public/Get-Company.ps1 b/SnipeitPS/Public/Get-Company.ps1 index c02088a..975dc2a 100644 --- a/SnipeitPS/Public/Get-Company.ps1 +++ b/SnipeitPS/Public/Get-Company.ps1 @@ -54,7 +54,7 @@ function Get-Company() [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/companies" diff --git a/SnipeitPS/Public/Get-Component.ps1 b/SnipeitPS/Public/Get-Component.ps1 index e601a02..bedac20 100644 --- a/SnipeitPS/Public/Get-Component.ps1 +++ b/SnipeitPS/Public/Get-Component.ps1 @@ -62,7 +62,7 @@ function Get-Component() { [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/components" diff --git a/SnipeitPS/Public/Get-Department.ps1 b/SnipeitPS/Public/Get-Department.ps1 index ef37e6c..8c9966c 100644 --- a/SnipeitPS/Public/Get-Department.ps1 +++ b/SnipeitPS/Public/Get-Department.ps1 @@ -57,7 +57,7 @@ function Get-Department() [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/departments" diff --git a/SnipeitPS/Public/Get-License.ps1 b/SnipeitPS/Public/Get-License.ps1 index e6f9da2..5bb370b 100644 --- a/SnipeitPS/Public/Get-License.ps1 +++ b/SnipeitPS/Public/Get-License.ps1 @@ -79,7 +79,7 @@ function Get-License() { [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/licenses" diff --git a/SnipeitPS/Public/Get-Manufacturer.ps1 b/SnipeitPS/Public/Get-Manufacturer.ps1 index f225070..8ebdd31 100644 --- a/SnipeitPS/Public/Get-Manufacturer.ps1 +++ b/SnipeitPS/Public/Get-Manufacturer.ps1 @@ -54,7 +54,7 @@ function Get-Manufacturer() [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/manufacturers" diff --git a/SnipeitPS/Public/Get-Model.ps1 b/SnipeitPS/Public/Get-Model.ps1 index d003bbc..a3e26a0 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -54,7 +54,7 @@ function Get-Model() [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/models" diff --git a/SnipeitPS/Public/Get-SnipeitLocation.ps1 b/SnipeitPS/Public/Get-SnipeitLocation.ps1 index 5b60c0d..a792aa9 100644 --- a/SnipeitPS/Public/Get-SnipeitLocation.ps1 +++ b/SnipeitPS/Public/Get-SnipeitLocation.ps1 @@ -54,7 +54,7 @@ function Get-SnipeitLocation() [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/locations" diff --git a/SnipeitPS/Public/Get-Status.ps1 b/SnipeitPS/Public/Get-Status.ps1 index 8e65108..ae8fb5c 100644 --- a/SnipeitPS/Public/Get-Status.ps1 +++ b/SnipeitPS/Public/Get-Status.ps1 @@ -54,7 +54,7 @@ function Get-Status() [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/statuslabels" diff --git a/SnipeitPS/Public/Get-Supplier.ps1 b/SnipeitPS/Public/Get-Supplier.ps1 index 311641c..8b167c7 100644 --- a/SnipeitPS/Public/Get-Supplier.ps1 +++ b/SnipeitPS/Public/Get-Supplier.ps1 @@ -54,7 +54,7 @@ function Get-Supplier() [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/suppliers" diff --git a/SnipeitPS/Public/Get-User.ps1 b/SnipeitPS/Public/Get-User.ps1 index 3cb99b1..2c3f9d3 100644 --- a/SnipeitPS/Public/Get-User.ps1 +++ b/SnipeitPS/Public/Get-User.ps1 @@ -60,7 +60,7 @@ function Get-User() { [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $apiurl = "$url/api/v1/users" diff --git a/SnipeitPS/Public/New-Accessory.ps1 b/SnipeitPS/Public/New-Accessory.ps1 index 46e3849..16216aa 100644 --- a/SnipeitPS/Public/New-Accessory.ps1 +++ b/SnipeitPS/Public/New-Accessory.ps1 @@ -41,7 +41,7 @@ function New-Accessory() { [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters if ($values['purchase_date']) { $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") diff --git a/SnipeitPS/Public/New-AssetMaintenance.ps1 b/SnipeitPS/Public/New-AssetMaintenance.ps1 index ceb2e29..b3bf214 100644 --- a/SnipeitPS/Public/New-AssetMaintenance.ps1 +++ b/SnipeitPS/Public/New-AssetMaintenance.ps1 @@ -36,7 +36,7 @@ function New-AssetMaintenance() { [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters if ($values['start_date']) { $values['start_date'] = $values['start_date'].ToString("yyyy-MM-dd") diff --git a/SnipeitPS/Public/New-Company.ps1 b/SnipeitPS/Public/New-Company.ps1 index 56aa590..620fd7a 100644 --- a/SnipeitPS/Public/New-Company.ps1 +++ b/SnipeitPS/Public/New-Company.ps1 @@ -39,7 +39,7 @@ function New-Company() [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $Body = $Values | ConvertTo-Json; diff --git a/SnipeitPS/Public/New-Component.ps1 b/SnipeitPS/Public/New-Component.ps1 index f07534c..755d48b 100644 --- a/SnipeitPS/Public/New-Component.ps1 +++ b/SnipeitPS/Public/New-Component.ps1 @@ -58,7 +58,7 @@ function New-Component() { [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters if ($values['purchase_date']) { $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") diff --git a/SnipeitPS/Public/New-CustomField.ps1 b/SnipeitPS/Public/New-CustomField.ps1 index bd93f6b..13557ad 100644 --- a/SnipeitPS/Public/New-CustomField.ps1 +++ b/SnipeitPS/Public/New-CustomField.ps1 @@ -46,7 +46,7 @@ function New-CustomField() [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters #Convert Values to JSON format $Body = $Values | ConvertTo-Json; diff --git a/SnipeitPS/Public/New-Department.ps1 b/SnipeitPS/Public/New-Department.ps1 index 867c0dc..3bcb51b 100644 --- a/SnipeitPS/Public/New-Department.ps1 +++ b/SnipeitPS/Public/New-Department.ps1 @@ -52,7 +52,7 @@ function New-Department() { [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $Body = $Values | ConvertTo-Json; diff --git a/SnipeitPS/Public/New-License.ps1 b/SnipeitPS/Public/New-License.ps1 index 44c24d4..f826416 100644 --- a/SnipeitPS/Public/New-License.ps1 +++ b/SnipeitPS/Public/New-License.ps1 @@ -56,7 +56,7 @@ function New-License() { [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters if ($values['expiration_date']) { $values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd") diff --git a/SnipeitPS/Public/New-Location.ps1 b/SnipeitPS/Public/New-Location.ps1 index 72e173d..e46e521 100644 --- a/SnipeitPS/Public/New-Location.ps1 +++ b/SnipeitPS/Public/New-Location.ps1 @@ -58,7 +58,7 @@ function New-Location() { [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $Body = $Values | ConvertTo-Json; diff --git a/SnipeitPS/Public/Set-Accessory.ps1 b/SnipeitPS/Public/Set-Accessory.ps1 index 276840a..9671081 100644 --- a/SnipeitPS/Public/Set-Accessory.ps1 +++ b/SnipeitPS/Public/Set-Accessory.ps1 @@ -41,7 +41,7 @@ function Set-Accessory() { [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters if ($values['purchase_date']) { $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") diff --git a/SnipeitPS/Public/Set-License.ps1 b/SnipeitPS/Public/Set-License.ps1 index be2e760..4e3df67 100644 --- a/SnipeitPS/Public/Set-License.ps1 +++ b/SnipeitPS/Public/Set-License.ps1 @@ -58,7 +58,7 @@ function Set-License() { [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters if ($values['expiration_date']) { $values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd") diff --git a/SnipeitPS/Public/Set-Model.ps1 b/SnipeitPS/Public/Set-Model.ps1 index e75bc9e..7494045 100644 --- a/SnipeitPS/Public/Set-Model.ps1 +++ b/SnipeitPS/Public/Set-Model.ps1 @@ -31,7 +31,7 @@ function Set-Model() { [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $Body = $Values | ConvertTo-Json; diff --git a/SnipeitPS/Public/Set-SnipeitLocation.ps1 b/SnipeitPS/Public/Set-SnipeitLocation.ps1 index ae1a24d..02930ad 100644 --- a/SnipeitPS/Public/Set-SnipeitLocation.ps1 +++ b/SnipeitPS/Public/Set-SnipeitLocation.ps1 @@ -82,7 +82,7 @@ function Set-SnipeitLocation() { [string]$apiKey ) - $Values = . Get-ParameterValue + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $Body = $Values | ConvertTo-Json; From d3fb9762abc52e50e33af1f43f32e277dc75b52b Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Thu, 11 Feb 2021 15:23:34 +0200 Subject: [PATCH 20/34] Fix for #77 and add activated as parameter --- SnipeitPS/Public/New-User.ps1 | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/SnipeitPS/Public/New-User.ps1 b/SnipeitPS/Public/New-User.ps1 index d18e21c..23eb3b0 100644 --- a/SnipeitPS/Public/New-User.ps1 +++ b/SnipeitPS/Public/New-User.ps1 @@ -68,11 +68,11 @@ function New-User() { [string]$lastName, [parameter(mandatory = $true)] - [string]$userName, + [string]$username, [string]$password, - [string]$jobTitle, + [string]$jobtitle, [string]$email, @@ -90,33 +90,27 @@ function New-User() { [bool]$ldap_user = $false, + [bool]$activated = $false, + [parameter(mandatory = $true)] [string]$url, [parameter(mandatory = $true)] [string]$apiKey ) - - $Values = @{ - first_name = $firstName - last_name = $lastName - username = $userName - - email = $email - phone = $phone - company_id = $company_id - location_id = $location_id - department_id = $department_id - manager_id = $manager_id - jobtitle = $jobTitle - employee_num = $employee_num - notes = "Imported using SnipeitPS Script" - activated = 1 + $Values= @{} + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters + if($Values.ContainsKey('firstname')) { + $Values['first_name']=$Values['firstname'] + $Values.Remove('firstname') } - + if($Values.ContainsKey('lastname')) { + $Values['last_name']=$Values['lastname'] + $Values.Remove('lastname') + } + if ($ldap_user -eq $false) { $ldap = @{ - password = $password password_confirmation = $password ldap_import = 0 } From ddb0036156d15e874f089dd212865607f635f019 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Thu, 11 Feb 2021 21:05:06 +0200 Subject: [PATCH 21/34] same parameter names as api and removed ldap logic --- SnipeitPS/Public/New-User.ps1 | 57 +++++++++++++++-------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/SnipeitPS/Public/New-User.ps1 b/SnipeitPS/Public/New-User.ps1 index 23eb3b0..ec77a10 100644 --- a/SnipeitPS/Public/New-User.ps1 +++ b/SnipeitPS/Public/New-User.ps1 @@ -5,16 +5,22 @@ .DESCRIPTION Long description - .PARAMETER firstName + .PARAMETER first_name Parameter description - .PARAMETER lastName + .PARAMETER last_name Parameter description - .PARAMETER userName + .PARAMETER username Parameter description - .PARAMETER jobTitle + .PARAMETER active + Parameter description + + .PARAMETER notes + Parameter description + + .PARAMETER jobtitle Parameter description .PARAMETER email @@ -38,8 +44,8 @@ .PARAMETER employee_num Parameter description - .PARAMETER ldap_user - Parameter description + .PARAMETER ldap_import + Mark user as import from ldap .PARAMETER url Parameter description @@ -62,16 +68,20 @@ function New-User() { Param( [parameter(mandatory = $true)] - [string]$firstName, + [string]$first_name, [parameter(mandatory = $true)] - [string]$lastName, + [string]$last_name, [parameter(mandatory = $true)] [string]$username, [string]$password, + [bool]$activated = $false, + + [string]$notes, + [string]$jobtitle, [string]$email, @@ -88,41 +98,22 @@ function New-User() { [string]$employee_num, - [bool]$ldap_user = $false, - - [bool]$activated = $false, + [bool]$ldap_import = $false, + [parameter(mandatory = $true)] [string]$url, [parameter(mandatory = $true)] [string]$apiKey ) - $Values= @{} + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - if($Values.ContainsKey('firstname')) { - $Values['first_name']=$Values['firstname'] - $Values.Remove('firstname') - } - if($Values.ContainsKey('lastname')) { - $Values['last_name']=$Values['lastname'] - $Values.Remove('lastname') + + if ($password ) { + $Values['password_confirmation'] = $password } - if ($ldap_user -eq $false) { - $ldap = @{ - password_confirmation = $password - ldap_import = 0 - } - $Values += $ldap - } - else { - $ldap = @{ - ldap_import = 1 - } - $Values += $ldap - } - $Body = $Values | ConvertTo-Json; $Parameters = @{ From a4bc6bb3f0865e72a54300108d688191698ad108 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Thu, 18 Feb 2021 19:43:26 +0200 Subject: [PATCH 22/34] Keep asset tag optional as in api+ more parameters --- SnipeitPS/Public/New-Asset.ps1 | 94 +++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 24 deletions(-) diff --git a/SnipeitPS/Public/New-Asset.ps1 b/SnipeitPS/Public/New-Asset.ps1 index 1362770..3513937 100644 --- a/SnipeitPS/Public/New-Asset.ps1 +++ b/SnipeitPS/Public/New-Asset.ps1 @@ -5,17 +5,42 @@ .DESCRIPTION Long description - .PARAMETER Tag - Asset Tag for the Asset - .PARAMETER Name - Name of the Asset + .PARAMETER status_id + Required Status ID of the asset, this can be got using Get-Status - .PARAMETER Status_id - Status ID of the asset, this can be got using Get-Status + .PARAMETER model_id + Required Model ID of the asset, this can be got using Get-Model - .PARAMETER Model_id - Model ID of the asset, this can be got using Get-Model + .PARAMETER name + Optional Name of the Asset + + .PARAMETER asset_tag + Asset Tag for the Asset, not required when snipe asset_tag autogeneration is on. + + .PARAMETER serial + Optional Serial number of the Asset + + .PARAMETER company_id + Optional Company id + + .PARAMETER order_number + Optional Order number + + .PARAMETER notes + Optional Notes + + .PARAMETER warranty_monhts + Optional Warranty lenght of the Asset in months + + .PARAMETER purchase_cost + Optional Purchase cost of the Asset + + .PARAMETER purchase_date + Optional Purchase cost of the Asset + + .PARAMETER rtd_location_id + Optional Default location id for the asset .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -41,16 +66,45 @@ function New-Asset() )] Param( - [string]$tag, + + [parameter(mandatory = $true)] + [int]$status_id, [parameter(mandatory = $true)] - [string]$Name, + [int]$model_id, - [parameter(mandatory = $true)] - [int]$Status_id, + [parameter(mandatory = $false)] + [string]$name, - [parameter(mandatory = $true)] - [int]$Model_id, + [parameter(mandatory = $false)] + [string]$asset_tag, + + [parameter(mandatory = $false)] + [string]$serial, + + [parameter(mandatory = $false)] + [int]$company_id, + + [parameter(mandatory = $false)] + [string]$order_number, + + [parameter(mandatory = $false)] + [string]$notes, + + [parameter(mandatory = $false)] + [int]$warranty_months, + + [parameter(mandatory = $false)] + [string]$purchase_cost, + + [parameter(mandatory = $false)] + [string]$purchase_date, + + [parameter(mandatory = $false)] + [int]$supplier_id, + + [parameter(mandatory = $false)] + [int]$rtd_location_id, [parameter(mandatory = $true)] [string]$url, @@ -61,16 +115,8 @@ function New-Asset() [hashtable] $customfields ) - $Values = @{ - "name" = $Name - "status_id" = $status_id - "model_id" = $model_id - } - - if ($PSBoundParameters.ContainsKey('tag')) - { - $Values += @{"asset_tag" = $tag} - } + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters + if ($customfields) { From 0708776249f9e930c88628cba0fac2b5662b4565 Mon Sep 17 00:00:00 2001 From: shcgitpf Date: Wed, 10 Mar 2021 11:48:26 +0000 Subject: [PATCH 23/34] Add 'parent_id' and fix documentation 'parent_id' is used by the SnipeIT API but was not present in this module meaning locations could be created, but not have a parent set which severely limited its usefulness. Adding parent_id allows for example, the creation of buildings under sites, and rooms under buildings. --- SnipeitPS/Public/New-Location.ps1 | 42 +++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/SnipeitPS/Public/New-Location.ps1 b/SnipeitPS/Public/New-Location.ps1 index 72e173d..2e58975 100644 --- a/SnipeitPS/Public/New-Location.ps1 +++ b/SnipeitPS/Public/New-Location.ps1 @@ -1,22 +1,40 @@ <# .SYNOPSIS - Add a new Model to Snipe-it asset system + Add a new Location to Snipe-it asset system .DESCRIPTION Long description .PARAMETER name - Name of the Asset Model + Name of the Location + + .PARAMETER address + Address line 1 of the location + + .PARAMETER address2 + Address line 2 of the location + + .PARAMETER state + Address State of the location + + .PARAMETER country + Country of the location + + .PARAMETER zip + The zip code of the location + + .PARAMETER ldap_ou + The LDAP OU of the location - .PARAMETER category_id - Category ID that the asset belongs to this can be got using Get-Category - - .PARAMETER manufacturer_id - Manufacturer ID that the asset belongs to this can be got using Get-Manufacturer - - .PARAMETER fieldset_id - Fieldset ID that the asset uses (Custom fields) + .PARAMETER parent_id + Parent location ID for the location + .PARAMETER currency + Currency used at the location + + .PARAMETER manager_id + The manager ID of the location + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -24,7 +42,7 @@ Users API Key for Snipeit, can be set using Set-Info command .EXAMPLE - New-Model -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1 + New-Location -name "Room 1" -address "123 Asset Street" -parent_id 14 #> function New-Location() { @@ -46,6 +64,8 @@ function New-Location() { [string]$country, [string]$zip, + + [int]$parent_id, [int]$manager_id, From 63f6ae12e216625adeb0d89c0924fbd3c6fe1cb2 Mon Sep 17 00:00:00 2001 From: shcgitpf Date: Thu, 11 Mar 2021 10:04:42 +0000 Subject: [PATCH 24/34] Updated for current API fields The API supports a 'PUT' for modifying parts of an asset, but most of the supported fields were missing (I need to be able to set a location for example which was missing). I've added all the current API fields and replaced the $values section with Get-ParameterValue. Not fully tested everything but looking good so far. --- SnipeitPS/Public/Set-Asset.ps1 | 65 ++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/SnipeitPS/Public/Set-Asset.ps1 b/SnipeitPS/Public/Set-Asset.ps1 index fd11788..56ab2da 100644 --- a/SnipeitPS/Public/Set-Asset.ps1 +++ b/SnipeitPS/Public/Set-Asset.ps1 @@ -1,6 +1,6 @@ <# .SYNOPSIS - Update a Asset in the Snipe-it asset system + Update a specific Asset in the Snipe-it asset system .DESCRIPTION Long description @@ -9,13 +9,46 @@ ID of the Asset .PARAMETER Name - Name of the Asset + Asset name .PARAMETER Status_id Status ID of the asset, this can be got using Get-Status .PARAMETER Model_id Model ID of the asset, this can be got using Get-Model + + .PARAMETER last_checkout + Date the asset was last checked out + + .PARAMETER assigned_to + The id of the user the asset is currently checked out to + + .PARAMETER company_id + The id of an associated company id + + .PARAMETER serial + Serial number of the asset + + .PARAMETER order_number + Order number for the asset + + .PARAMETER warranty_months + Number of months for the asset warranty + + .PARAMETER purchase_cost + Purchase cost of the asset, without a currency symbol + + .PARAMETER purchase_date + Date of asset purchase + + .PARAMETER requestable + Whether or not the asset can be requested by users with the permission to request assets + + .PARAMETER archived + Whether or not the asset is archived. Archived assets cannot be checked out and do not show up in the deployable asset screens + + .PARAMETER rtd_location_id + The id that corresponds to the location where the asset is usually located when not checked out .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -49,6 +82,28 @@ function Set-Asset() [string]$Status_id, [string]$Model_id, + + [DateTime]$last_checkout, + + [int]$assigned_to, + + [int]$company_id, + + [string]$serial, + + [string]$order_number, + + [int]$warranty_months, + + [double]$purchase_cost, + + [DateTime]$purchase_date, + + [bool]$requestable, + + [bool]$archived, + + [int]$rtd_location_id, [parameter(mandatory = $true)] [string]$url, @@ -59,11 +114,7 @@ function Set-Asset() [hashtable] $customfields ) - $Values = @{ - "name" = $Name - "status_id" = $status_id - "model_id" = $model_id - } + $Values = . Get-ParameterValue if ($customfields) { From d3cf37173d9c6d7f4d36790abd24511cdc136a44 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sat, 15 May 2021 23:20:27 +0300 Subject: [PATCH 25/34] removed utf-bom from file --- SnipeitPS/SnipeItPS.psd1 | Bin 9732 -> 5162 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index d3148361197c9a024c88ee08029e9a78a2a3eb49..fbbbaa66d85c8401a23d9cea6152b3c9cd1f73b7 100644 GIT binary patch literal 5162 zcmc&&TW{Mo6n@XIIDj9V42fH}X<8I0P$QQ%K#~S=((RR&D4UB!sw8FC82aD$@nTta zBzM_>&TrNszjME_x7VX*44pF1cowr!-l< zr?KVbj7z#^l}x$bI-%ry8oqfk9KLwt`mxTLsF4K0Hc<6=|+zIy}AEjEz21dEmVmh;AEc{eJHy=E~Q{Kp4 znp3qp2ax^bfLuUqN6&ypc}^bAkmiQ#IZp>QuQP6Z%s6*?g*j!FOq@$tF6@#@t>!SV zi_9n1ZC-{5w`zgFm~rqM-ClZ;W1Q2-7;X{Jl1;rnHUDcNMNt(nRtTvm!|wvNTNv_? zV-LyYR7egLzEwiE%d<9(+VL%x~qCj=0A%;18bvf z$JXRpkfHrSX@&BQg#Z~wP7Uo_>Yi}xfzbsMP*6hC*IV4cd z%u&yUYr4CP=pee_FO)9ex&Ou>fON4~`L1>~dO1mq7VuFK!zUKE@Rv-<6OjqfVcm6C ze-V&sL&YGy@lY!+8{WH!Jploth<|rcNtsqfGtv%yxtO?7r{o&b4kn)jS&}M}%DSda z3z4S@)2SgQ(-k4*IY-fP(Tz^0mxul+lf;V>4Tx#Y(Ba*Tff9wk9B_4$Y6ujJ<%E6q(XvXg|uA#LkDXk^iG*5zLj0o!>`CA>n zaI{^%@borcI6|9MogA%^UK747uzGAe!%^Lk+G;aLM3HzJ5RPyuGu4LHCEQPfbCjk> zqa?K8Cn@E1=py-2g_TfGDLn;Si~i513%pCMgfdU=X-tHm7s zh*D;m)3Id6>*^Zn^X7oK3l!+LEH?^MxwL46#IUEIIrJGbGwY%&=*rTt1YjVIj0$d< zmjm72uZ-)JEch!5>(OA1_;TU8a%8dj(Ghxd&!(6dd_VDfe`67LB4eo~tcYb0DoTSs%gxj_~O?tYO$!#Ux*qm1a`?#fx!Su+pCetQ|;MvI02K?}Ft z$IR@2ES!B8eB$>m_d?`#!_xgHR*h|7%(d?GPk}Kz3HT17kG0NVWZ2pXws9|UxC`_S z(-{))Mp_qQV{JnJ+MgmB)Bx7Fj%XSmt57CQ_VB+-Mi2&otQ(hYWP7B0lPiY4(JO)NaOv(`#;^psEo7g frQgw9M|7`!N4Fk7Sh(hjUg|gnT0^WKdwYKa;rt#N literal 9732 zcmeI1+fE!u5Qh6Uk@5~JaRH733APhQks^5o#zw*iad2|G2Oz}kAqyB=kzYN@|8-IB z>7ALKSz?r2SZJBund<5~{8e35^Y>pX;j8dvSP7l*JWRqcT!r&+tY4$h3*&GWPW0;{ zTzsP~DUnWcKN&xM{1bSLR|tzVbYsuTa8iK1-NjVRB))=or~+y7_L*W1>0 zcpa^Dp}nv}N1rRn*^hTSx_2_Sf6~DAF77$c%Ouzg8?vT()OS75E>rzsCHE(OeH0)f8AHTupAG#ikBOW@7 zs2RsyPU0Or;I>b?qsP;5B)r1c^gIbah96|FhvL!K|8*f~pl_S{_E6Xw#Cv_AsxPW_ z(LU1WzMeb~4fjB7f6h`}Nrw!Er$zoirkvUlfQ9SgBlkdAj3Q-v&NeIa8Eou!khBP zhG@G&$GNUaE@E*edBD>wV4tB-o@=umpQjAr5te+2RZb!b2hz))_p}oc02-&_JrQ?9 zrRTgnALN*<+tYM^6|IiM7qTvxN2{(PX*Wt@{>`&7&&f{5(emV0^4Y0=yFYTRpG#Vz zY9zfz;)-q9uUh+GA~ndm7EMQz@QoD*1qt!{X{5wr*qxX?i{IKavPn%AaRG~@fkT|BfQY*a;R@RdSW^0 zT2E)nM$2M~oNy?7+POfKf>=i-SSRChnt*W=CfVndObRki|Os zRXi0rmB-@vUOM@Cx~+Sc(vT=E>-Xs_>v9jY-$;K}Gn`99BJ@gEG6VMHY$c~z?qAah zz8Cgm=1rF3TT}f0|7>lVw6WUuwZY#10rC?_cQ-Hd~Ybu;+33M!$ZI z)db(Vvf)sb!oyow&+$=~q+2UTbuLNg444K7oXS+BR8@SVW(4!pY3S;89p{17TaKPn zp?4yB;sSJ!;~9so#t|=e$`eS=Po>!a#>OS3+35~vScxi>b!QSj7SejmbK0**ZG~Wb$+8c)xY62_uX~O%V@tm z)_nhEWZsGRrc)+@{u{ZAGAtwed@Pk?lx&9&$Z6yVi;rTQ@-(liichKj@hE*Uwz2hw z&V8+$?|Hw?I^Z&LJS%Wcx;*n*RL9g#JkL^0{Vxz_;T z&oU=E&Tj78)PyqwS}J4gho;`Yc2psQ@1g8Me?qHu>B754ck+S!e8%0IPNEBqQ384y`!xn=E8eUbZH_dXibv{eaIpbAPMqz0qmC z(3`AEm$tNYF?K3p2`q=bn>lQW7E7K=TCCS*h0iVMr`yw89l$x*W{sV|?6ec31Z*^~ zqsnBW!bzQaxh5;79jqs8-Y4~w)Wv(U9k}&=w|TwwoL53vFXGGUCC;KISuM7SfM(hQ zNrY6`vJJJ(udF&~Bg>Ka+6h`GHCgGpC8o=?%VOF&w8wN>VVG`%(X?hcjQYCeFzT!J z6a_@|INH44n+KvHi?pRr{M%yKS1ga=w35nuF@~MC8Dp-o*OQC#OPThi@Hv(&i}3EN zdQLTH?Q^cOqHJJ(iFSo+e<Mk_DI_5K`)}{D ziZ=VyeQZ7x9Z3Q@G`xl1JMs;uE>c>rjI_Kh-PRqGo#`F#fcRx^Q;R-imQ|cM!#PI* zzo?y{be>dr#d&VkY}?`{w`r2fJdob8d*7GKUPtBBE0Xn4Qk_Px^n})_3s7QeqAgZs5MLRzOOGU z`dbs9k0dFXs7}J~qGP^LZ#kP2I^DmMlc@kxK#L{I)yQGkAi9vgega)DHx_*0Wh?M|}a&0Vm`)be6T; P%Csr2DBI}6$IA8}BkS(R From 7dde5ce1de5fc92956b812b55cebc493b9212c7f Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 16 May 2021 08:37:04 +0300 Subject: [PATCH 26/34] Dont return requesttype and customfields parameters by default --- SnipeitPS/Private/Get-ParameterValue.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SnipeitPS/Private/Get-ParameterValue.ps1 b/SnipeitPS/Private/Get-ParameterValue.ps1 index 2cbb971..5fb5f4a 100644 --- a/SnipeitPS/Private/Get-ParameterValue.ps1 +++ b/SnipeitPS/Private/Get-ParameterValue.ps1 @@ -26,13 +26,13 @@ function Get-ParameterValue { $Parameters , - [string[]]$DefaultExcludeParameter = @("id", "url", "apiKey", 'Debug', 'Verbose') + [string[]]$DefaultExcludeParameter = @("id", "url", "apiKey", 'Debug', 'Verbose','RequestType','customfields') ) if ($MyInvocation.Line[($MyInvocation.OffsetInLine - 1)] -ne '.') { throw "Get-ParameterValue must be dot-sourced, like this: . Get-ParameterValues" } - + $ParameterValues = @{} foreach ($parameter in $Parameters.GetEnumerator()) { From 997af62157c3b253afb599a5c853b5ba26971c57 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 16 May 2021 11:36:20 +0300 Subject: [PATCH 27/34] Added missing extension for Remove-User.ps1 --- .../Public/{Remove-User => Remove-User.ps1} | 0 SnipeitPS/SnipeItPS.psd1 | Bin 9760 -> 9808 bytes 2 files changed, 0 insertions(+), 0 deletions(-) rename SnipeitPS/Public/{Remove-User => Remove-User.ps1} (100%) diff --git a/SnipeitPS/Public/Remove-User b/SnipeitPS/Public/Remove-User.ps1 similarity index 100% rename from SnipeitPS/Public/Remove-User rename to SnipeitPS/Public/Remove-User.ps1 diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 2e6d7a91381405e7e5b8fd85f9f17b704ec3e091..d495c73340a4c14032d42275a4c4fc1143434c47 100644 GIT binary patch delta 28 kcmZ4BbHQiBF3HJpq7suANb<3VG88kUG8ApzE}6*#0GwF~q5uE@ delta 12 TcmccMv%qJ=F3HWWB-3~RDRKq0 From b8923b2029050ab5fabd003e4c12e211b604b1f6 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 16 May 2021 12:31:04 +0300 Subject: [PATCH 28/34] fix issue #58 --- SnipeitPS/Public/Set-AssetOwner.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SnipeitPS/Public/Set-AssetOwner.ps1 b/SnipeitPS/Public/Set-AssetOwner.ps1 index 3ecbc1c..84c82b1 100644 --- a/SnipeitPS/Public/Set-AssetOwner.ps1 +++ b/SnipeitPS/Public/Set-AssetOwner.ps1 @@ -23,7 +23,7 @@ function Set-AssetOwner() ) $Values = @{ - "id" = $assigned_id + "id" = $id "checkout_to_type" = $checkout_to_type } From 981e90e1037cfe1359cf43273e684c6ed725d8b1 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 16 May 2021 13:13:23 +0300 Subject: [PATCH 29/34] fix for #35, get-user by email or username --- SnipeitPS/Public/Get-User.ps1 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/SnipeitPS/Public/Get-User.ps1 b/SnipeitPS/Public/Get-User.ps1 index 2c3f9d3..934a6d0 100644 --- a/SnipeitPS/Public/Get-User.ps1 +++ b/SnipeitPS/Public/Get-User.ps1 @@ -33,7 +33,7 @@ Get-User -url "https://assets.example.com" -token "token..." | Where-Object {$_. function Get-User() { Param( [string]$search, - + [string]$id, [int]$company_id, @@ -44,6 +44,10 @@ function Get-User() { [int]$department_id, + [string]$username, + + [string]$email, + [ValidateSet("asc", "desc")] [string]$order = "desc", @@ -61,15 +65,15 @@ function Get-User() { ) $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - + $apiurl = "$url/api/v1/users" if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/users/$id" + $apiurl= "$url/api/v1/users/$id" } $Parameters = @{ Uri = $apiurl @@ -85,8 +89,8 @@ function Get-User() { while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-User @callargs + $callargs['limit'] = $limit + $res=Get-User @callargs $res if ($res.count -lt $limit) { break From 312eb8e8df69cfa1470370915d2919e9aae9fffb Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 16 May 2021 13:41:49 +0300 Subject: [PATCH 30/34] added alias tag to asset_tag parameter to keep backward compatibility --- SnipeitPS/Public/New-Asset.ps1 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SnipeitPS/Public/New-Asset.ps1 b/SnipeitPS/Public/New-Asset.ps1 index 3513937..e20cd01 100644 --- a/SnipeitPS/Public/New-Asset.ps1 +++ b/SnipeitPS/Public/New-Asset.ps1 @@ -25,7 +25,7 @@ Optional Company id .PARAMETER order_number - Optional Order number + Optional Order number .PARAMETER notes Optional Notes @@ -66,7 +66,7 @@ function New-Asset() )] Param( - + [parameter(mandatory = $true)] [int]$status_id, @@ -77,6 +77,7 @@ function New-Asset() [string]$name, [parameter(mandatory = $false)] + [Alias('tag')] [string]$asset_tag, [parameter(mandatory = $false)] @@ -116,7 +117,7 @@ function New-Asset() ) $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - + if ($customfields) { From 738b4c60519448be182b1454092c86d6ccb78d55 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Mon, 17 May 2021 07:55:25 +0300 Subject: [PATCH 31/34] If apirequest fails, dont continue, just throw error --- SnipeitPS/Private/Invoke-SnipeitMethod.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 index 8400267..02817e2 100644 --- a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 +++ b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 @@ -72,8 +72,9 @@ $webResponse = Invoke-WebRequest @splatParameters } catch { - Write-Verbose "[$($MyInvocation.MyCommand.Name)] Failed to get an answer from the server" - $webResponse = $_.Exception.Response + #Write-Verbose "[$($MyInvocation.MyCommand.Name)] Failed to get an answer from the server" + #$webResponse = $_.Exception.Response + throw "[$($MyInvocation.MyCommand.Name)] Failed to get an answer from the server. $($_.Exception.Response)" } Write-Debug "[$($MyInvocation.MyCommand.Name)] Executed WebRequest. Access $webResponse to see details" From d2805b1ffdb90eb9782556ff90743783a0642a9c Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Mon, 17 May 2021 08:39:16 +0300 Subject: [PATCH 32/34] Revert "If api request to snipe fails, don't continue, just throw error" --- SnipeitPS/Private/Invoke-SnipeitMethod.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 index 02817e2..8400267 100644 --- a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 +++ b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 @@ -72,9 +72,8 @@ $webResponse = Invoke-WebRequest @splatParameters } catch { - #Write-Verbose "[$($MyInvocation.MyCommand.Name)] Failed to get an answer from the server" - #$webResponse = $_.Exception.Response - throw "[$($MyInvocation.MyCommand.Name)] Failed to get an answer from the server. $($_.Exception.Response)" + Write-Verbose "[$($MyInvocation.MyCommand.Name)] Failed to get an answer from the server" + $webResponse = $_.Exception.Response } Write-Debug "[$($MyInvocation.MyCommand.Name)] Executed WebRequest. Access $webResponse to see details" From 5761f15eabe8b9750d057540bb88e34b3b6aaa2c Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Mon, 17 May 2021 10:07:17 +0300 Subject: [PATCH 33/34] remove whitespace --- SnipeitPS/Public/Get-Accessory.ps1 | 4 ++-- SnipeitPS/Public/Get-Asset.ps1 | 12 ++++++------ SnipeitPS/Public/Get-AssetMaintenance.ps1 | 4 ++-- SnipeitPS/Public/Get-Category.ps1 | 10 +++++----- SnipeitPS/Public/Get-Company.ps1 | 8 ++++---- SnipeitPS/Public/Get-Component.ps1 | 10 +++++----- SnipeitPS/Public/Get-Department.ps1 | 10 +++++----- SnipeitPS/Public/Get-License.ps1 | 10 +++++----- SnipeitPS/Public/Get-Manufacturer.ps1 | 8 ++++---- SnipeitPS/Public/Get-Model.ps1 | 10 +++++----- SnipeitPS/Public/Get-SnipeitLocation.ps1 | 10 +++++----- SnipeitPS/Public/Get-Status.ps1 | 10 +++++----- SnipeitPS/Public/Get-Supplier.ps1 | 10 +++++----- SnipeitPS/Public/New-Category.ps1 | 2 +- SnipeitPS/Public/New-Location.ps1 | 18 +++++++++--------- SnipeitPS/Public/New-User.ps1 | 10 +++++----- SnipeitPS/Public/Set-Components.ps1 | 2 +- SnipeitPS/Public/Set-SnipeitLocation.ps1 | 4 ++-- 18 files changed, 76 insertions(+), 76 deletions(-) diff --git a/SnipeitPS/Public/Get-Accessory.ps1 b/SnipeitPS/Public/Get-Accessory.ps1 index 1f9a639..a40d23f 100644 --- a/SnipeitPS/Public/Get-Accessory.ps1 +++ b/SnipeitPS/Public/Get-Accessory.ps1 @@ -76,8 +76,8 @@ function Get-Accessory() { while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-Accessory @callargs + $callargs['limit'] = $limit + $res=Get-Accessory @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index f6dc4d2..7d996dd 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -131,21 +131,21 @@ function Get-Asset() { 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" + $apiurl= "$url/api/v1/hardware/$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" + $apiurl= "$url/api/v1/hardware/bytag/$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" + $apiurl= "$url/api/v1/hardware/byserial/$asset_serial" } $Parameters = @{ @@ -162,8 +162,8 @@ function Get-Asset() { while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-Asset @callargs + $callargs['limit'] = $limit + $res=Get-Asset @callargs $res if ( $res.count -lt $limit) { break @@ -175,7 +175,7 @@ function Get-Asset() { $result } - + } diff --git a/SnipeitPS/Public/Get-AssetMaintenance.ps1 b/SnipeitPS/Public/Get-AssetMaintenance.ps1 index 1cb2108..f470da5 100644 --- a/SnipeitPS/Public/Get-AssetMaintenance.ps1 +++ b/SnipeitPS/Public/Get-AssetMaintenance.ps1 @@ -78,8 +78,8 @@ function Get-AssetMaintenance() { while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-AssetMaintenance @callargs + $callargs['limit'] = $limit + $res=Get-AssetMaintenance @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/Get-Category.ps1 b/SnipeitPS/Public/Get-Category.ps1 index bee35c8..39959be 100644 --- a/SnipeitPS/Public/Get-Category.ps1 +++ b/SnipeitPS/Public/Get-Category.ps1 @@ -55,15 +55,15 @@ function Get-Category() ) $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - + $apiurl = "$url/api/v1/categories" if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/categories/$id" + $apiurl= "$url/api/v1/categories/$id" } $Parameters = @{ @@ -80,8 +80,8 @@ function Get-Category() while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-Category @callargs + $callargs['limit'] = $limit + $res=Get-Category @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/Get-Company.ps1 b/SnipeitPS/Public/Get-Company.ps1 index 975dc2a..7fd5798 100644 --- a/SnipeitPS/Public/Get-Company.ps1 +++ b/SnipeitPS/Public/Get-Company.ps1 @@ -61,9 +61,9 @@ function Get-Company() if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/companies/$id" + $apiurl= "$url/api/v1/companies/$id" } $Parameters = @{ @@ -80,8 +80,8 @@ function Get-Company() while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-Company @callargs + $callargs['limit'] = $limit + $res=Get-Company @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/Get-Component.ps1 b/SnipeitPS/Public/Get-Component.ps1 index bedac20..71a028e 100644 --- a/SnipeitPS/Public/Get-Component.ps1 +++ b/SnipeitPS/Public/Get-Component.ps1 @@ -34,7 +34,7 @@ Get-Component -url "https://assets.example.com" -token "token..." | Where-Object function Get-Component() { Param( [string]$search, - + [string]$id, [int]$category_id, @@ -69,9 +69,9 @@ function Get-Component() { if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/components/$id" + $apiurl= "$url/api/v1/components/$id" } $Parameters = @{ @@ -88,8 +88,8 @@ function Get-Component() { while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-Component @callargs + $callargs['limit'] = $limit + $res=Get-Component @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/Get-Department.ps1 b/SnipeitPS/Public/Get-Department.ps1 index 8c9966c..85f6b13 100644 --- a/SnipeitPS/Public/Get-Department.ps1 +++ b/SnipeitPS/Public/Get-Department.ps1 @@ -58,15 +58,15 @@ function Get-Department() ) $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - + $apiurl = "$url/api/v1/departments" if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/departments/$id" + $apiurl= "$url/api/v1/departments/$id" } $Parameters = @{ @@ -83,8 +83,8 @@ function Get-Department() while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-Department @callargs + $callargs['limit'] = $limit + $res=Get-Department @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/Get-License.ps1 b/SnipeitPS/Public/Get-License.ps1 index 5bb370b..5d207d6 100644 --- a/SnipeitPS/Public/Get-License.ps1 +++ b/SnipeitPS/Public/Get-License.ps1 @@ -80,15 +80,15 @@ function Get-License() { ) $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - + $apiurl = "$url/api/v1/licenses" if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/licenses/$id" + $apiurl= "$url/api/v1/licenses/$id" } $Parameters = @{ @@ -105,8 +105,8 @@ function Get-License() { while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-License @callargs + $callargs['limit'] = $limit + $res=Get-License @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/Get-Manufacturer.ps1 b/SnipeitPS/Public/Get-Manufacturer.ps1 index 8ebdd31..2260148 100644 --- a/SnipeitPS/Public/Get-Manufacturer.ps1 +++ b/SnipeitPS/Public/Get-Manufacturer.ps1 @@ -61,9 +61,9 @@ function Get-Manufacturer() if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/manufacturers/$id" + $apiurl= "$url/api/v1/manufacturers/$id" } $Parameters = @{ @@ -80,8 +80,8 @@ function Get-Manufacturer() while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-Manufacturer @callargs + $callargs['limit'] = $limit + $res=Get-Manufacturer @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/Get-Model.ps1 b/SnipeitPS/Public/Get-Model.ps1 index a3e26a0..76d7d37 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -55,15 +55,15 @@ function Get-Model() ) $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - + $apiurl = "$url/api/v1/models" if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/models/$id" + $apiurl= "$url/api/v1/models/$id" } $Parameters = @{ @@ -80,8 +80,8 @@ function Get-Model() while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-Model @callargs + $callargs['limit'] = $limit + $res=Get-Model @callargs $res if ($res.count -ne $limit ) { break diff --git a/SnipeitPS/Public/Get-SnipeitLocation.ps1 b/SnipeitPS/Public/Get-SnipeitLocation.ps1 index a792aa9..3d61c9a 100644 --- a/SnipeitPS/Public/Get-SnipeitLocation.ps1 +++ b/SnipeitPS/Public/Get-SnipeitLocation.ps1 @@ -35,7 +35,7 @@ function Get-SnipeitLocation() { Param( [string]$search, - + [string]$id, [ValidateSet("asc", "desc")] @@ -61,9 +61,9 @@ function Get-SnipeitLocation() if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/locations/$id" + $apiurl= "$url/api/v1/locations/$id" } $Parameters = @{ @@ -80,8 +80,8 @@ function Get-SnipeitLocation() while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitLocation @callargs + $callargs['limit'] = $limit + $res=Get-SnipeitLocation @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/Get-Status.ps1 b/SnipeitPS/Public/Get-Status.ps1 index ae8fb5c..6a6f477 100644 --- a/SnipeitPS/Public/Get-Status.ps1 +++ b/SnipeitPS/Public/Get-Status.ps1 @@ -55,15 +55,15 @@ function Get-Status() ) $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - + $apiurl = "$url/api/v1/statuslabels" if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/statuslabels/$id" + $apiurl= "$url/api/v1/statuslabels/$id" } $Parameters = @{ @@ -80,8 +80,8 @@ function Get-Status() while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-Status @callargs + $callargs['limit'] = $limit + $res=Get-Status @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/Get-Supplier.ps1 b/SnipeitPS/Public/Get-Supplier.ps1 index 8b167c7..4cbbb98 100644 --- a/SnipeitPS/Public/Get-Supplier.ps1 +++ b/SnipeitPS/Public/Get-Supplier.ps1 @@ -55,15 +55,15 @@ function Get-Supplier() ) $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - + $apiurl = "$url/api/v1/suppliers" if ($search -and $id ) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " } - + if ($id) { - $apiurl= "$url/api/v1/suppliers/$id" + $apiurl= "$url/api/v1/suppliers/$id" } $Parameters = @{ @@ -80,8 +80,8 @@ function Get-Supplier() while ($true) { $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-Supplier @callargs + $callargs['limit'] = $limit + $res=Get-Supplier @callargs $res if ($res.count -lt $limit) { break diff --git a/SnipeitPS/Public/New-Category.ps1 b/SnipeitPS/Public/New-Category.ps1 index c750a14..fc5c0e1 100644 --- a/SnipeitPS/Public/New-Category.ps1 +++ b/SnipeitPS/Public/New-Category.ps1 @@ -63,7 +63,7 @@ function New-Category() if ($checkin_email) { $Values += @{"checkin_email" = $true} } - + $Body = $Values | ConvertTo-Json; $Parameters = @{ diff --git a/SnipeitPS/Public/New-Location.ps1 b/SnipeitPS/Public/New-Location.ps1 index 66e425f..d15cc93 100644 --- a/SnipeitPS/Public/New-Location.ps1 +++ b/SnipeitPS/Public/New-Location.ps1 @@ -7,22 +7,22 @@ .PARAMETER name Name of the Location - + .PARAMETER address Address line 1 of the location - + .PARAMETER address2 Address line 2 of the location - + .PARAMETER state Address State of the location - + .PARAMETER country Country of the location - + .PARAMETER zip The zip code of the location - + .PARAMETER ldap_ou The LDAP OU of the location @@ -31,10 +31,10 @@ .PARAMETER currency Currency used at the location - + .PARAMETER manager_id The manager ID of the location - + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -64,7 +64,7 @@ function New-Location() { [string]$country, [string]$zip, - + [int]$parent_id, [int]$manager_id, diff --git a/SnipeitPS/Public/New-User.ps1 b/SnipeitPS/Public/New-User.ps1 index ec77a10..49d4507 100644 --- a/SnipeitPS/Public/New-User.ps1 +++ b/SnipeitPS/Public/New-User.ps1 @@ -100,20 +100,20 @@ function New-User() { [bool]$ldap_import = $false, - + [parameter(mandatory = $true)] [string]$url, [parameter(mandatory = $true)] [string]$apiKey ) - + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - + if ($password ) { - $Values['password_confirmation'] = $password + $Values['password_confirmation'] = $password } - + $Body = $Values | ConvertTo-Json; $Parameters = @{ diff --git a/SnipeitPS/Public/Set-Components.ps1 b/SnipeitPS/Public/Set-Components.ps1 index 92f44f8..b6f95fe 100644 --- a/SnipeitPS/Public/Set-Components.ps1 +++ b/SnipeitPS/Public/Set-Components.ps1 @@ -26,7 +26,7 @@ function Set-Component() $Body = $Values | ConvertTo-Json; $Parameters = @{ - Uri = "$url/api/v1/components/$component_id" + Uri = "$url/api/v1/components/$id" Method = 'Patch' Body = $Body Token = $apiKey diff --git a/SnipeitPS/Public/Set-SnipeitLocation.ps1 b/SnipeitPS/Public/Set-SnipeitLocation.ps1 index 02930ad..e517d07 100644 --- a/SnipeitPS/Public/Set-SnipeitLocation.ps1 +++ b/SnipeitPS/Public/Set-SnipeitLocation.ps1 @@ -44,7 +44,7 @@ .EXAMPLE Set-SnipeitLocation -id 123 -name "Some storage" -parent_id 100 - + #> function Set-SnipeitLocation() { [CmdletBinding( @@ -82,7 +82,7 @@ function Set-SnipeitLocation() { [string]$apiKey ) - $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters $Body = $Values | ConvertTo-Json; From fe1bcc52f7d514de23bdc84fd77f5e1bad557b7f Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Mon, 17 May 2021 15:46:06 +0300 Subject: [PATCH 34/34] Version bump to 1.1.x --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c16c57c..b5df4ce 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,7 +14,7 @@ environment: PSGalleryAPIKey: secure: UdM6qhf5B0G8liHhUrwWERCZr44iSqmg4jUq0lwlTjZs4KyeoiwnBzdej0phqIAm -version: 1.0.{build} +version: 1.1.{build} # Don't rebuild when I tag a release on GitHub skip_tags: true @@ -72,4 +72,4 @@ deploy: prerelease: false on: branch: master # release from master branch only - appveyor_repo_tag: false # deploy on tag push only \ No newline at end of file + appveyor_repo_tag: false # deploy on tag push only