From efe36f81f24d8b54be634f20029e40d1828733cc Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sat, 2 Jan 2021 14:19:15 +0200 Subject: [PATCH 01/12] Added Set-SnipeitLocation --- SnipeitPS/SnipeItPS.psd1 | Bin 9596 -> 9660 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 780aa3c855eff24d20b6fc42db8090c49bb5cdd0..1a5873b62e142b0e6221911f91864a4c4d0a2bb4 100644 GIT binary patch delta 20 ccmez4wa0sdnB?Sj5(<-*L=-lQNv81t09S Date: Sat, 2 Jan 2021 14:20:04 +0200 Subject: [PATCH 02/12] Added Set-SnipeitLocation --- SnipeitPS/Public/Set-SnipeitLocation.ps1 | 102 +++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 SnipeitPS/Public/Set-SnipeitLocation.ps1 diff --git a/SnipeitPS/Public/Set-SnipeitLocation.ps1 b/SnipeitPS/Public/Set-SnipeitLocation.ps1 new file mode 100644 index 0000000..ae1a24d --- /dev/null +++ b/SnipeitPS/Public/Set-SnipeitLocation.ps1 @@ -0,0 +1,102 @@ +<# + .SYNOPSIS + Updates Location in Snipe-it asset system + + .DESCRIPTION + Long description + + .PARAMETER name + Name of Location + + .PARAMETER address + Address line 1 + + .PARAMETER address2 + Address line 2 + + .PARAMETER state + Address State + + .PARAMETER country + Address Contry + + .PARAMETER zip + Address zipcode + + .PARAMETER state + Address State + + .PARAMETER manager_id + Location manager as id + + .PARAMETER ldap_ou + LDAP OU of Location + + .PARAMETER parent_id + Parent location as id + + .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 + Set-SnipeitLocation -id 123 -name "Some storage" -parent_id 100 + + +#> +function Set-SnipeitLocation() { + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [int]$id, + + [ValidateLength(3, 255)] + [string]$name, + + [string]$address, + + [string]$address2, + + [string]$state, + + [string]$country, + + [string]$zip, + + [int]$manager_id, + + [string]$ldap_ou, + + [int]$parent_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = . Get-ParameterValue + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/locations/$id" + Method = 'PUT' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} + From c88dd833235fd39b6808f7a6a261d25a8a5f0cb4 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Mon, 4 Jan 2021 08:53:47 +0200 Subject: [PATCH 03/12] Get-asset with -asset_tag --- SnipeitPS/Public/Get-Asset.ps1 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index ab1f4f4..2ebc8cf 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -60,6 +60,8 @@ function Get-Asset() { Param( [string]$search, + [string]$asset_tag, + [int]$order_number, [int]$model_id, @@ -98,8 +100,17 @@ function Get-Asset() { $SearchParameter = . Get-ParameterValue + $apiuri = "$url/api/v1/hardware" + + if ($asset_tag) { + if ( $search) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -asset_tag parameter , not both " + } + $apiuri= "$url/api/v1/hardware/bytag/$asset_tag" + } + $Parameters = @{ - Uri = "$url/api/v1/hardware" + Uri = "$apiuri" Method = 'Get' GetParameters = $SearchParameter Token = $apiKey From 9afb3a1be68b1dab83ab03cd199f6335e4e1101f Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Mon, 4 Jan 2021 08:59:23 +0200 Subject: [PATCH 04/12] Added synopsis for asset_tag --- SnipeitPS/Public/Get-Asset.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 2ebc8cf..00a7298 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -5,6 +5,9 @@ .PARAMETER search A text string to search the assets data +.PARAMETER asset_tag +Specify exact asset tag to query + .PARAMETER order_number Optionally restrict asset results to this order number From d78d5d52817eb1ef50b69d92fe491634de66688f Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Mon, 4 Jan 2021 09:01:31 +0200 Subject: [PATCH 05/12] Added example for asset_tag --- SnipeitPS/Public/Get-Asset.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 00a7298..b266e4b 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -58,6 +58,9 @@ Get-Asset -search "myMachine" -url "https://assets.example.com" -token "token... .EXAMPLE Get-Asset -search "myMachine" -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Asset -asset_tag "myAssetTag" -url "https://assets.example.com" -token "token..." #> function Get-Asset() { Param( From 2925106297aff15f91568af09facedf6e4e9b8d3 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 17 Jan 2021 05:42:25 +0200 Subject: [PATCH 06/12] Get-asset by serial --- SnipeitPS/Public/Get-Asset.ps1 | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index b266e4b..cbcff27 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -8,6 +8,9 @@ A text string to search the assets data .PARAMETER asset_tag Specify exact asset tag to query +.PARAMETER asset_serial +Specify exact asset serial to query + .PARAMETER order_number Optionally restrict asset results to this order number @@ -68,6 +71,8 @@ function Get-Asset() { [string]$asset_tag, + [string]$asset_serial, + [int]$order_number, [int]$model_id, @@ -106,15 +111,27 @@ function Get-Asset() { $SearchParameter = . Get-ParameterValue + $apiuri = "$url/api/v1/hardware" + if ($search -and ($asset_tag -or $asset_serial)) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search , -asset_tag or -asset_serial parameter , not both " + } + if ($asset_tag) { - if ( $search) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -asset_tag parameter , not both " + if ( $search -or $asset_serial) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search , -asset_tag or -asset_serial parameter , not both " } $apiuri= "$url/api/v1/hardware/bytag/$asset_tag" } + if ($asset_serial) { + if ( $search -or $asset_tag) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search , -asset_tag or -asset_serial parameter , not both " + } + $apiuri= "$url/api/v1/hardware/byserial/$asset_serial" + } + $Parameters = @{ Uri = "$apiuri" Method = 'Get' From c3cb7d14b6b7e60173b7bd8b02dd0dce8d1a39c4 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 17 Jan 2021 06:28:08 +0200 Subject: [PATCH 07/12] Get assets and other items by id --- SnipeitPS/Public/Get-Asset.ps1 | 20 ++++++++++++++++---- SnipeitPS/Public/Get-Category.ps1 | 20 +++++++++++++++++++- SnipeitPS/Public/Get-Company.ps1 | 20 +++++++++++++++++++- SnipeitPS/Public/Get-Component.ps1 | 20 +++++++++++++++++++- SnipeitPS/Public/Get-Department.ps1 | 20 +++++++++++++++++++- SnipeitPS/Public/Get-License.ps1 | 20 +++++++++++++++++++- SnipeitPS/Public/Get-Manufacturer.ps1 | 20 +++++++++++++++++++- SnipeitPS/Public/Get-Model.ps1 | 20 +++++++++++++++++++- SnipeitPS/Public/Get-SnipeitLocation.ps1 | 20 +++++++++++++++++++- SnipeitPS/Public/Get-Status.ps1 | 20 +++++++++++++++++++- SnipeitPS/Public/Get-Supplier.ps1 | 20 +++++++++++++++++++- SnipeitPS/Public/Get-User.ps1 | 21 +++++++++++++++++++-- 12 files changed, 225 insertions(+), 16 deletions(-) diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index cbcff27..1a84f4e 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -5,6 +5,9 @@ .PARAMETER search A text string to search the assets data +.PARAMETER id +A text string to search the assets data + .PARAMETER asset_tag Specify exact asset tag to query @@ -69,6 +72,8 @@ function Get-Asset() { Param( [string]$search, + [string]$id, + [string]$asset_tag, [string]$asset_serial, @@ -114,20 +119,27 @@ function Get-Asset() { $apiuri = "$url/api/v1/hardware" - if ($search -and ($asset_tag -or $asset_serial)) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search , -asset_tag or -asset_serial parameter , not both " + 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) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter" + } + $apiuri= "$url/api/v1/hardware/$id" } if ($asset_tag) { if ( $search -or $asset_serial) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search , -asset_tag or -asset_serial parameter , not both " + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter" } $apiuri= "$url/api/v1/hardware/bytag/$asset_tag" } if ($asset_serial) { if ( $search -or $asset_tag) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search , -asset_tag or -asset_serial parameter , not both " + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of-search , -asset_tag or -asset_serial parameter" } $apiuri= "$url/api/v1/hardware/byserial/$asset_serial" } diff --git a/SnipeitPS/Public/Get-Category.ps1 b/SnipeitPS/Public/Get-Category.ps1 index 0c697c9..e9cc736 100644 --- a/SnipeitPS/Public/Get-Category.ps1 +++ b/SnipeitPS/Public/Get-Category.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Categories +.PARAMETER search +A text string to search the Categories data + +.PARAMETER id +A id of specific Category + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -21,6 +27,8 @@ function Get-Category() Param( [string]$search, + [string]$id, + [ValidateSet("asc", "desc")] [string]$order = "desc", @@ -36,9 +44,19 @@ function Get-Category() ) $SearchParameter = . Get-ParameterValue + + $apiurl = "$url/api/v1/categories" + + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/categories/$id" + } $Parameters = @{ - Uri = "$url/api/v1/categories" + Uri = $apiurl Method = 'Get' Token = $apiKey GetParameters = $SearchParameter diff --git a/SnipeitPS/Public/Get-Company.ps1 b/SnipeitPS/Public/Get-Company.ps1 index 1f20ba2..98c6244 100644 --- a/SnipeitPS/Public/Get-Company.ps1 +++ b/SnipeitPS/Public/Get-Company.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Companies +.PARAMETER search +A text string to search the Companies data + +.PARAMETER id +A id of specific Company + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -21,6 +27,8 @@ function Get-Company() Param( [string]$search, + [string]$id, + [ValidateSet("asc", "desc")] [string]$order = "desc", @@ -37,8 +45,18 @@ function Get-Company() $SearchParameter = . Get-ParameterValue + $apiurl = "$url/api/v1/companies" + + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/companies/$id" + } + $Parameters = @{ - Uri = "$url/api/v1/companies" + Uri = $apiurl Method = 'Get' Token = $apiKey GetParameters = $SearchParameter diff --git a/SnipeitPS/Public/Get-Component.ps1 b/SnipeitPS/Public/Get-Component.ps1 index e55616d..8f7d510 100644 --- a/SnipeitPS/Public/Get-Component.ps1 +++ b/SnipeitPS/Public/Get-Component.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Components +.PARAMETER search +A text string to search the Components data + +.PARAMETER id +A id of specific Component + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -19,6 +25,8 @@ Get-Component -url "https://assets.example.com" -token "token..." | Where-Object function Get-Component() { Param( [string]$search, + + [string]$id, [int]$category_id, @@ -45,8 +53,18 @@ function Get-Component() { $SearchParameter = . Get-ParameterValue + $apiurl = "$url/api/v1/components" + + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/components/$id" + } + $Parameters = @{ - Uri = "$url/api/v1/components" + Uri = $apiurl Method = 'Get' Token = $apiKey GetParameters = $SearchParameter diff --git a/SnipeitPS/Public/Get-Department.ps1 b/SnipeitPS/Public/Get-Department.ps1 index 840409e..aed2394 100644 --- a/SnipeitPS/Public/Get-Department.ps1 +++ b/SnipeitPS/Public/Get-Department.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Departments +.PARAMETER search +A text string to search the Departments data + +.PARAMETER id +A id of specific Department + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -21,6 +27,8 @@ function Get-Department() Param( [string]$search, + [string]$id, + [ValidateSet("asc", "desc")] [string]$order = "desc", @@ -39,9 +47,19 @@ function Get-Department() ) $SearchParameter = . Get-ParameterValue + + $apiurl = "$url/api/v1/departments" + + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/departments/$id" + } $Parameters = @{ - Uri = "$url/api/v1/departments" + Uri = $apiurl Method = 'Get' Token = $apiKey GetParameters = $SearchParameter diff --git a/SnipeitPS/Public/Get-License.ps1 b/SnipeitPS/Public/Get-License.ps1 index fccb45e..78020a9 100644 --- a/SnipeitPS/Public/Get-License.ps1 +++ b/SnipeitPS/Public/Get-License.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Licenses +.PARAMETER search +A text string to search the Licenses data + +.PARAMETER id +A id of specific License + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -20,6 +26,8 @@ function Get-License() { Param( [string]$search, + [string]$id, + [string]$name, [int] $company_id, @@ -60,9 +68,19 @@ function Get-License() { ) $SearchParameter = . Get-ParameterValue + + $apiurl = "$url/api/v1/licenses" + + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/licenses/$id" + } $Parameters = @{ - Uri = "$url/api/v1/licenses" + Uri = $apiurl Method = 'Get' Token = $apiKey GetParameters = $SearchParameter diff --git a/SnipeitPS/Public/Get-Manufacturer.ps1 b/SnipeitPS/Public/Get-Manufacturer.ps1 index b55798e..c4c9433 100644 --- a/SnipeitPS/Public/Get-Manufacturer.ps1 +++ b/SnipeitPS/Public/Get-Manufacturer.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Manufacturers +.PARAMETER search +A text string to search the Manufactures data + +.PARAMETER id +A id of specific Manufactuter + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -21,6 +27,8 @@ function Get-Manufacturer() Param( [string]$search, + [string]$id, + [ValidateSet("asc", "desc")] [string]$order = "desc", @@ -37,8 +45,18 @@ function Get-Manufacturer() $SearchParameter = . Get-ParameterValue + $apiurl = "$url/api/v1/manufacturers" + + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/manufacturers/$id" + } + $Parameters = @{ - Uri = "$url/api/v1/manufacturers" + Uri = $apiurl Method = 'Get' Token = $apiKey GetParameters = $SearchParameter diff --git a/SnipeitPS/Public/Get-Model.ps1 b/SnipeitPS/Public/Get-Model.ps1 index c15d7c7..8c2396d 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Models +.PARAMETER search +A text string to search the Models data + +.PARAMETER id +A id of specific model + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -21,6 +27,8 @@ function Get-Model() Param( [string]$search, + [string]$id, + [ValidateSet("asc", "desc")] [string]$order = "desc", @@ -36,9 +44,19 @@ function Get-Model() ) $SearchParameter = . Get-ParameterValue + + $apiurl = "$url/api/v1/models" + + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/models/$id" + } $Parameters = @{ - Uri = "$url/api/v1/models" + Uri = $apiurl Method = 'Get' Token = $apiKey GetParameters = $SearchParameter diff --git a/SnipeitPS/Public/Get-SnipeitLocation.ps1 b/SnipeitPS/Public/Get-SnipeitLocation.ps1 index 0030a89..ce95e2b 100644 --- a/SnipeitPS/Public/Get-SnipeitLocation.ps1 +++ b/SnipeitPS/Public/Get-SnipeitLocation.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Locations +.PARAMETER search +A text string to search the Locations data + +.PARAMETER id +A id of specific Location + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -20,6 +26,8 @@ function Get-SnipeitLocation() { Param( [string]$search, + + [string]$id, [ValidateSet("asc", "desc")] [string]$order = "desc", @@ -37,8 +45,18 @@ function Get-SnipeitLocation() $SearchParameter = . Get-ParameterValue + $apiurl = "$url/api/v1/locations" + + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/locations/$id" + } + $Parameters = @{ - Uri = "$url/api/v1/locations" + Uri = $apiurl Method = 'Get' Token = $apiKey GetParameters = $SearchParameter diff --git a/SnipeitPS/Public/Get-Status.ps1 b/SnipeitPS/Public/Get-Status.ps1 index a5f4f89..21eecff 100644 --- a/SnipeitPS/Public/Get-Status.ps1 +++ b/SnipeitPS/Public/Get-Status.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Status Labels +.PARAMETER search +A text string to search the Status Labels data + +.PARAMETER id +A id of specific Status Label + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -21,6 +27,8 @@ function Get-Status() Param( [string]$search, + [string]$id, + [ValidateSet("asc", "desc")] [string]$order = "desc", @@ -36,9 +44,19 @@ function Get-Status() ) $SearchParameter = . Get-ParameterValue + + $apiurl = "$url/api/v1/statuslabels" + + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/statuslabels/$id" + } $Parameters = @{ - Uri = "$url/api/v1/statuslabels" + Uri = $apiurl Method = 'Get' Token = $apiKey GetParameters = $SearchParameter diff --git a/SnipeitPS/Public/Get-Supplier.ps1 b/SnipeitPS/Public/Get-Supplier.ps1 index f556cd4..c0874eb 100644 --- a/SnipeitPS/Public/Get-Supplier.ps1 +++ b/SnipeitPS/Public/Get-Supplier.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Suppliers +.PARAMETER search +A text string to search the Supliers data + +.PARAMETER id +A id of specific Suplier + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -21,6 +27,8 @@ function Get-Supplier() Param( [string]$search, + [string]$id, + [ValidateSet("asc", "desc")] [string]$order = "desc", @@ -36,9 +44,19 @@ function Get-Supplier() ) $SearchParameter = . Get-ParameterValue + + $apiurl = "$url/api/v1/suppliers" + + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/suppliers/$id" + } $Parameters = @{ - Uri = "$url/api/v1/suppliers" + Uri = $apiurl Method = 'Get' Token = $apiKey GetParameters = $SearchParameter diff --git a/SnipeitPS/Public/Get-User.ps1 b/SnipeitPS/Public/Get-User.ps1 index 00132fd..f3c4c7d 100644 --- a/SnipeitPS/Public/Get-User.ps1 +++ b/SnipeitPS/Public/Get-User.ps1 @@ -2,6 +2,12 @@ .SYNOPSIS # Gets a list of Snipe-it Users +.PARAMETER search +A text string to search the User data + +.PARAMETER id +A id of specific User + .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -18,6 +24,8 @@ Get-User -url "https://assets.example.com" -token "token..." | Where-Object {$_. function Get-User() { Param( [string]$search, + + [string]$id, [int]$company_id, @@ -41,10 +49,19 @@ function Get-User() { [string]$apiKey ) - $SearchParameter = . Get-ParameterValue + $SearchParameter = . Get-ParameterValue + + $apiurl = "$url/api/v1/users" + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $apiuri= "$url/api/v1/users/$id" + } $Parameters = @{ - Uri = "$url/api/v1/users" + Uri = $apiurl Method = 'Get' GetParameters = $SearchParameter Token = $apiKey From f688b32c5070ccd459110e1af3f85142bffcc518 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 17 Jan 2021 06:48:05 +0200 Subject: [PATCH 08/12] Get ids --- SnipeitPS/Private/Get-ParameterValue.ps1 | 2 +- SnipeitPS/Public/Get-Asset.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SnipeitPS/Private/Get-ParameterValue.ps1 b/SnipeitPS/Private/Get-ParameterValue.ps1 index f8f7882..0c8fc65 100644 --- a/SnipeitPS/Private/Get-ParameterValue.ps1 +++ b/SnipeitPS/Private/Get-ParameterValue.ps1 @@ -26,7 +26,7 @@ function Get-ParameterValue { # The $PSBoundParameters for the caller -- DO NOT pass this (dot-source Get-ParameterValues instead) $BoundParameters = $PSBoundParameters, - [string[]]$DefaultExcludeParameter = @("id", "url", "apiKey", 'Debug', 'Verbose') + [string[]]$DefaultExcludeParameter = @("url", "apiKey", 'Debug', 'Verbose') ) if ($MyInvocation.Line[($MyInvocation.OffsetInLine - 1)] -ne '.') { diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 1a84f4e..202399c 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -131,7 +131,7 @@ function Get-Asset() { } if ($asset_tag) { - if ( $search -or $asset_serial) { + if ( $search -or $asset_serial -or $id) { Throw "[$($MyInvocation.MyCommand.Name)] Please specify only one of -search , -asset_tag or -asset_serial parameter" } $apiuri= "$url/api/v1/hardware/bytag/$asset_tag" From 953a3453fcdf717a2baabf0745e43bd5d8b7db0a Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 17 Jan 2021 07:09:19 +0200 Subject: [PATCH 09/12] Fixed copypasted typo --- SnipeitPS/Private/Get-ParameterValue.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SnipeitPS/Private/Get-ParameterValue.ps1 b/SnipeitPS/Private/Get-ParameterValue.ps1 index 0c8fc65..f8f7882 100644 --- a/SnipeitPS/Private/Get-ParameterValue.ps1 +++ b/SnipeitPS/Private/Get-ParameterValue.ps1 @@ -26,7 +26,7 @@ function Get-ParameterValue { # The $PSBoundParameters for the caller -- DO NOT pass this (dot-source Get-ParameterValues instead) $BoundParameters = $PSBoundParameters, - [string[]]$DefaultExcludeParameter = @("url", "apiKey", 'Debug', 'Verbose') + [string[]]$DefaultExcludeParameter = @("id", "url", "apiKey", 'Debug', 'Verbose') ) if ($MyInvocation.Line[($MyInvocation.OffsetInLine - 1)] -ne '.') { From 608d8f04ca8247af2c3bb3e5f795143d85a6f3ae Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 17 Jan 2021 07:11:22 +0200 Subject: [PATCH 10/12] Fixed copypasted typo --- SnipeitPS/Public/Get-Asset.ps1 | 10 +++++----- 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 | 8 ++++---- SnipeitPS/Public/Get-SnipeitLocation.ps1 | 2 +- SnipeitPS/Public/Get-Status.ps1 | 2 +- SnipeitPS/Public/Get-Supplier.ps1 | 2 +- SnipeitPS/Public/Get-User.ps1 | 2 +- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 202399c..97f9d1f 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -117,7 +117,7 @@ function Get-Asset() { $SearchParameter = . Get-ParameterValue - $apiuri = "$url/api/v1/hardware" + $apiurl = "$url/api/v1/hardware" 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" @@ -127,25 +127,25 @@ 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" } - $apiuri= "$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" } - $apiuri= "$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" } - $apiuri= "$url/api/v1/hardware/byserial/$asset_serial" + $apiurl= "$url/api/v1/hardware/byserial/$asset_serial" } $Parameters = @{ - Uri = "$apiuri" + Uri = $apiurl Method = 'Get' GetParameters = $SearchParameter Token = $apiKey diff --git a/SnipeitPS/Public/Get-Category.ps1 b/SnipeitPS/Public/Get-Category.ps1 index e9cc736..21e1ad2 100644 --- a/SnipeitPS/Public/Get-Category.ps1 +++ b/SnipeitPS/Public/Get-Category.ps1 @@ -52,7 +52,7 @@ function Get-Category() } if ($id) { - $apiuri= "$url/api/v1/categories/$id" + $apiurl= "$url/api/v1/categories/$id" } $Parameters = @{ diff --git a/SnipeitPS/Public/Get-Company.ps1 b/SnipeitPS/Public/Get-Company.ps1 index 98c6244..04134b4 100644 --- a/SnipeitPS/Public/Get-Company.ps1 +++ b/SnipeitPS/Public/Get-Company.ps1 @@ -52,7 +52,7 @@ function Get-Company() } if ($id) { - $apiuri= "$url/api/v1/companies/$id" + $apiurl= "$url/api/v1/companies/$id" } $Parameters = @{ diff --git a/SnipeitPS/Public/Get-Component.ps1 b/SnipeitPS/Public/Get-Component.ps1 index 8f7d510..961930e 100644 --- a/SnipeitPS/Public/Get-Component.ps1 +++ b/SnipeitPS/Public/Get-Component.ps1 @@ -60,7 +60,7 @@ function Get-Component() { } if ($id) { - $apiuri= "$url/api/v1/components/$id" + $apiurl= "$url/api/v1/components/$id" } $Parameters = @{ diff --git a/SnipeitPS/Public/Get-Department.ps1 b/SnipeitPS/Public/Get-Department.ps1 index aed2394..8164a6d 100644 --- a/SnipeitPS/Public/Get-Department.ps1 +++ b/SnipeitPS/Public/Get-Department.ps1 @@ -55,7 +55,7 @@ function Get-Department() } if ($id) { - $apiuri= "$url/api/v1/departments/$id" + $apiurl= "$url/api/v1/departments/$id" } $Parameters = @{ diff --git a/SnipeitPS/Public/Get-License.ps1 b/SnipeitPS/Public/Get-License.ps1 index 78020a9..f87e2cb 100644 --- a/SnipeitPS/Public/Get-License.ps1 +++ b/SnipeitPS/Public/Get-License.ps1 @@ -76,7 +76,7 @@ function Get-License() { } if ($id) { - $apiuri= "$url/api/v1/licenses/$id" + $apiurl= "$url/api/v1/licenses/$id" } $Parameters = @{ diff --git a/SnipeitPS/Public/Get-Manufacturer.ps1 b/SnipeitPS/Public/Get-Manufacturer.ps1 index c4c9433..c22d1f9 100644 --- a/SnipeitPS/Public/Get-Manufacturer.ps1 +++ b/SnipeitPS/Public/Get-Manufacturer.ps1 @@ -52,7 +52,7 @@ function Get-Manufacturer() } if ($id) { - $apiuri= "$url/api/v1/manufacturers/$id" + $apiurl= "$url/api/v1/manufacturers/$id" } $Parameters = @{ diff --git a/SnipeitPS/Public/Get-Model.ps1 b/SnipeitPS/Public/Get-Model.ps1 index 8c2396d..44e5e98 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -27,7 +27,7 @@ function Get-Model() Param( [string]$search, - [string]$id, + [int]$id, [ValidateSet("asc", "desc")] [string]$order = "desc", @@ -52,14 +52,14 @@ function Get-Model() } if ($id) { - $apiuri= "$url/api/v1/models/$id" + $apiurl= "$url/api/v1/models/id/$id" } - + write-host "ID $id, -- $SearchParameter" $Parameters = @{ Uri = $apiurl Method = 'Get' Token = $apiKey - GetParameters = $SearchParameter + #GetParameters = $SearchParameter } $result = Invoke-SnipeitMethod @Parameters diff --git a/SnipeitPS/Public/Get-SnipeitLocation.ps1 b/SnipeitPS/Public/Get-SnipeitLocation.ps1 index ce95e2b..18f8e4c 100644 --- a/SnipeitPS/Public/Get-SnipeitLocation.ps1 +++ b/SnipeitPS/Public/Get-SnipeitLocation.ps1 @@ -52,7 +52,7 @@ function Get-SnipeitLocation() } if ($id) { - $apiuri= "$url/api/v1/locations/$id" + $apiurl= "$url/api/v1/locations/$id" } $Parameters = @{ diff --git a/SnipeitPS/Public/Get-Status.ps1 b/SnipeitPS/Public/Get-Status.ps1 index 21eecff..816c8b1 100644 --- a/SnipeitPS/Public/Get-Status.ps1 +++ b/SnipeitPS/Public/Get-Status.ps1 @@ -52,7 +52,7 @@ function Get-Status() } if ($id) { - $apiuri= "$url/api/v1/statuslabels/$id" + $apiurl= "$url/api/v1/statuslabels/$id" } $Parameters = @{ diff --git a/SnipeitPS/Public/Get-Supplier.ps1 b/SnipeitPS/Public/Get-Supplier.ps1 index c0874eb..a92481f 100644 --- a/SnipeitPS/Public/Get-Supplier.ps1 +++ b/SnipeitPS/Public/Get-Supplier.ps1 @@ -52,7 +52,7 @@ function Get-Supplier() } if ($id) { - $apiuri= "$url/api/v1/suppliers/$id" + $apiurl= "$url/api/v1/suppliers/$id" } $Parameters = @{ diff --git a/SnipeitPS/Public/Get-User.ps1 b/SnipeitPS/Public/Get-User.ps1 index f3c4c7d..c9b8858 100644 --- a/SnipeitPS/Public/Get-User.ps1 +++ b/SnipeitPS/Public/Get-User.ps1 @@ -58,7 +58,7 @@ function Get-User() { } if ($id) { - $apiuri= "$url/api/v1/users/$id" + $apiurl= "$url/api/v1/users/$id" } $Parameters = @{ Uri = $apiurl From 3c064938e12af48856df1f6f7f610c2ab5030813 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 17 Jan 2021 07:13:23 +0200 Subject: [PATCH 11/12] Fixed copypasted typo --- 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 44e5e98..4ce4382 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -52,7 +52,7 @@ function Get-Model() } if ($id) { - $apiurl= "$url/api/v1/models/id/$id" + $apiurl= "$url/api/v1/models/$id" } write-host "ID $id, -- $SearchParameter" $Parameters = @{ From a09eb8c23e0de436d78c01629ae588600eb355eb Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 17 Jan 2021 07:14:32 +0200 Subject: [PATCH 12/12] Fixed copypasted typo --- 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 4ce4382..57eded7 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -54,7 +54,7 @@ function Get-Model() if ($id) { $apiurl= "$url/api/v1/models/$id" } - write-host "ID $id, -- $SearchParameter" + $Parameters = @{ Uri = $apiurl Method = 'Get'