From 4385d8709361076831e5f463b6291c1ac4bb4d03 Mon Sep 17 00:00:00 2001 From: Tim Murphy Date: Mon, 29 Jun 2020 18:50:43 -0500 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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()