From ac842e3d6a92a26857ceea259444b80c4a6d6719 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 13 Jun 2021 18:13:22 +0300 Subject: [PATCH 01/10] manage categories --- SnipeitPS/Public/New-SnipeitCategory.ps1 | 79 +++++++++--------- SnipeitPS/Public/Remove-SnipeitCategory.ps1 | 2 +- SnipeitPS/Public/Set-SnipeitCategory.ps1 | 90 +++++++++++++++++++++ 3 files changed, 130 insertions(+), 41 deletions(-) create mode 100644 SnipeitPS/Public/Set-SnipeitCategory.ps1 diff --git a/SnipeitPS/Public/New-SnipeitCategory.ps1 b/SnipeitPS/Public/New-SnipeitCategory.ps1 index 02aa68a..62ca0e9 100644 --- a/SnipeitPS/Public/New-SnipeitCategory.ps1 +++ b/SnipeitPS/Public/New-SnipeitCategory.ps1 @@ -8,11 +8,8 @@ Name of new category to be created .PARAMETER type Type of new category to be created (asset, accessory, consumable, component, license) -.PARAMETER url -URL of Snipeit system, can be set using Set-SnipeitInfo command - -.PARAMETER apiKey -User's API Key for Snipeit, can be set using Set-SnipeitInfo command +.PARAMETER eula_text +This allows you to customize your EULAs for specific types of assets .PARAMETER use_default_eula If switch is present, use the primary default EULA @@ -23,6 +20,12 @@ 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 +.PARAMETER url +URL of Snipeit system, can be set using Set-SnipeitInfo command + +.PARAMETER apiKey +User's API Key for Snipeit, can be set using Set-SnipeitInfo command + .EXAMPLE New-SnipeitCategory -name "Laptops" -category_type asset -url "Snipe-IT URL here..." -apiKey "API key here..." #> @@ -42,51 +45,47 @@ function New-SnipeitCategory() [ValidateSet("asset", "accessory", "consumable", "component", "license")] [string]$category_type, - [parameter(mandatory = $true)] - [string]$url, + [string]$eula_text, - [parameter(mandatory = $true)] - [string]$apiKey, [switch]$use_default_eula, [switch]$require_acceptance, - [switch]$checkin_email + [switch]$checkin_email, + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + if($eula_text -and $use_default_eula){ + throw 'Dont use -use_defalt_eula if -eula_text is set' + } - $Values = @{ - "name" = $name - "category_type" = $category_type + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + + $Body = $Values | ConvertTo-Json; } - if ($use_default_eula) { - $Values += @{"use_default_eula" = $true} + process { + + $Parameters = @{ + Uri = "$url/api/v1/categories" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - - 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 } diff --git a/SnipeitPS/Public/Remove-SnipeitCategory.ps1 b/SnipeitPS/Public/Remove-SnipeitCategory.ps1 index ee864a4..873858b 100644 --- a/SnipeitPS/Public/Remove-SnipeitCategory.ps1 +++ b/SnipeitPS/Public/Remove-SnipeitCategory.ps1 @@ -18,7 +18,7 @@ Get-SnipeitCategory -search something | Remove-SnipeitCategory #> -function Remove-SnipeitModel () +function Remove-SnipeitCategory () { [CmdletBinding( SupportsShouldProcess = $true, diff --git a/SnipeitPS/Public/Set-SnipeitCategory.ps1 b/SnipeitPS/Public/Set-SnipeitCategory.ps1 new file mode 100644 index 0000000..a1603e9 --- /dev/null +++ b/SnipeitPS/Public/Set-SnipeitCategory.ps1 @@ -0,0 +1,90 @@ +<# +.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, license) + +.PARAMETER url +URL of Snipeit system, can be set using Set-SnipeitInfo command + +.PARAMETER apiKey +User's API Key for Snipeit, can be set using Set-SnipeitInfo command + +.PARAMETER use_default_eula +If switch is present, use the primary default EULA + +.PARAMETER eula_text +This allows you to customize your EULAs for specific types of assets + +.PARAMETER require_acceptance +If switch is present, require users to confirm acceptance of assets in this category + +.PARAMETER checkin_email +Should the user be emailed the EULA and/or an acceptance confirmation email when this item is checked in? + +.EXAMPLE +Set-SnipeitCategory -id 4 -name "Laptops" +#> + +function Set-SnipeitCategory() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [int[]]$id, + + [string]$name, + + [ValidateSet("asset", "accessory", "consumable", "component", "license")] + [string]$category_type, + + [string]$eula_text, + + [bool]$use_default_eula, + + [bool]$require_acceptance, + + [bool]$checkin_email, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + + ) + + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + + $Body = $Values | ConvertTo-Json; + } + + process { + foreach($category_id in $id){ + $Parameters = @{ + Uri = "$url/api/v1/categories/$category_id" + Method = 'Put' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result + } + } +} From 621ee767093104a77ffedc85080c58c497ba1bf6 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 13 Jun 2021 18:17:05 +0300 Subject: [PATCH 02/10] add set-snipeitcompany --- SnipeitPS/Public/Set-SnipeitCompany.ps1 | 70 +++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 SnipeitPS/Public/Set-SnipeitCompany.ps1 diff --git a/SnipeitPS/Public/Set-SnipeitCompany.ps1 b/SnipeitPS/Public/Set-SnipeitCompany.ps1 new file mode 100644 index 0000000..050e20c --- /dev/null +++ b/SnipeitPS/Public/Set-SnipeitCompany.ps1 @@ -0,0 +1,70 @@ +<# +.SYNOPSIS +Updates company name + +.DESCRIPTION +Updates companyt name on Snipe-It system + +.PARAMETER id +ID number of company + +.PARAMETER name +Company name + +.PARAMETER url +URL of Snipeit system, can be set using Set-SnipeitInfo command + +.PARAMETER apiKey +User's API Key for Snipeit, can be set using Set-SnipeitInfo command + +.EXAMPLE +An example + +.NOTES +General notes +#> +function Set-SnipeitCompany() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Medium" + )] + + Param( + [parameter(mandatory = $true,ValueFromPipelineByPropertyName)] + [int[]]$id, + + [parameter(mandatory = $true)] + [string]$name, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + begin{ + $values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + + $Body = $values | ConvertTo-Json; + } + + process{ + foreach($company_id in $id){ + $Parameters = @{ + Uri = "$url/api/v1/companies/$companyid" + Method = 'Patch' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result + } + } +} From b35230e3b8a63dfd151dc5337bbe252654b00d62 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 13 Jun 2021 18:29:14 +0300 Subject: [PATCH 03/10] get-set snipeitcustomfield --- SnipeitPS/Public/New-SnipeitCustomField.ps1 | 80 +++++++++++---- SnipeitPS/Public/Set-SnipeitCustomField.ps1 | 108 ++++++++++++++++++++ 2 files changed, 166 insertions(+), 22 deletions(-) create mode 100644 SnipeitPS/Public/Set-SnipeitCustomField.ps1 diff --git a/SnipeitPS/Public/New-SnipeitCustomField.ps1 b/SnipeitPS/Public/New-SnipeitCustomField.ps1 index d39807d..454394c 100644 --- a/SnipeitPS/Public/New-SnipeitCustomField.ps1 +++ b/SnipeitPS/Public/New-SnipeitCustomField.ps1 @@ -5,8 +5,29 @@ .DESCRIPTION Add a new Custom Field to Snipe-it asset system - .PARAMETER Name - Name of the Custom Field + .PARAMETER name + The field's name, which is also the form label + + .PARAMETER element + Form field type that should be displayed. + + .PARAMETER field_values + In the case of list boxes, etc, this should be a list of the options available + + .PARAMETER show_in_email + Whether or not to show the custom field in email notifications + + .PARAMETER format + How the field should be validated + + .PARAMETER custom_format + In the case of format 'CUSTOM REGEX', this should be validation regex this field + + .PARAMETER field_encrypted + Whether the field should be encrypted. (This can cause issues if you change it after the field was created.) + + .PARAMETER help_text + Any additional text you wish to display under the new form field to make it clearer what the gauges should be. .PARAMETER url URL of Snipeit system, can be set using Set-SnipeitInfo command @@ -27,17 +48,25 @@ function New-SnipeitCustomField() Param( [parameter(mandatory = $true)] - [string]$Name, + [string]$name, - [string]$HelpText, + [string]$help_text, - [string]$Element = "text", + [parameter(mandatory = $true)] + [ValidateSet('text','textarea','listbox','checkbox','radio')] + [string]$element , - [string]$Format = "ANY", + [parameter(mandatory = $true)] + [ValidateSet('ANY','CUSTOM REGEX','ALPHA','ALPHA-DASH','NUMERIC','ALPHA-NUMERIC','EMAIL','DATE','URL','IP','IPV4','IPV6','MAC','BOOLEAN')] + [string]$format, - [bool]$field_encrypted, + [string]$field_values, - [string]$CustomFormat, + [bool]$field_encrypted=$false, + + [bool]$show_in_email=$false, + + [string]$custom_format, [parameter(mandatory = $true)] [string]$url, @@ -46,24 +75,31 @@ function New-SnipeitCustomField() [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + if ($format -eq 'CUSTOM REGEX' -and (-not $custom_format)) { + throw "Please specify regex validation with -custom_format when using -format 'CUSTOM REGEX'" + } - $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - #Convert Values to JSON format - $Body = $Values | ConvertTo-Json; + $Body = $Values | ConvertTo-Json; - $Parameters = @{ - Uri = "$url/api/v1/fields" - Method = 'post' - Body = $Body - Token = $apiKey + $Parameters = @{ + Uri = "$url/api/v1/fields" + Method = 'post' + Body = $Body + Token = $apiKey + } } - If ($PSCmdlet.ShouldProcess("ShouldProcess?")) - { - $result = Invoke-SnipeitMethod @Parameters - } + process{ + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } - $result + $result + } } + diff --git a/SnipeitPS/Public/Set-SnipeitCustomField.ps1 b/SnipeitPS/Public/Set-SnipeitCustomField.ps1 new file mode 100644 index 0000000..de84f8d --- /dev/null +++ b/SnipeitPS/Public/Set-SnipeitCustomField.ps1 @@ -0,0 +1,108 @@ +<# + .SYNOPSIS + Add a new Custom Field to Snipe-it asset system + + .DESCRIPTION + Add a new Custom Field to Snipe-it asset system + + .PARAMETER name + The field's name, which is also the form label + + .PARAMETER element + Form field type that should be displayed. + + .PARAMETER field_values + In the case of list boxes, etc, this should be a list of the options available + + .PARAMETER show_in_email + Whether or not to show the custom field in email notifications + + .PARAMETER format + How the field should be validated + + .PARAMETER custom_format + In the case of format 'CUSTOM REGEX', this should be validation regex this field + + .PARAMETER field_encrypted + Whether the field should be encrypted. (This can cause issues if you change it after the field was created.) + + .PARAMETER help_text + Any additional text you wish to display under the new form field to make it clearer what the gauges should be. + + .PARAMETER url + URL of Snipeit system, can be set using Set-SnipeitInfo command + + .PARAMETER apiKey + Users API Key for Snipeit, can be set using Set-SnipeitInfo command + + .EXAMPLE + New-SnipeitCustomField -Name "AntivirusInstalled" -Format "BOOLEAN" -HelpText "Is AntiVirus installed on Asset" +#> + +function Set-SnipeitCustomField() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true,ValueFromPipelineByPropertyName)] + [int[]]$id, + + [string]$name, + + [string]$help_text, + + [parameter(Mandatory=$true)] + [ValidateSet('text','textarea','listbox','checkbox','radio')] + [string]$element , + + [ValidateSet('ANY','CUSTOM REGEX','ALPHA','ALPHA-DASH','NUMERIC','ALPHA-NUMERIC','EMAIL','DATE','URL','IP','IPV4','IPV6','MAC','BOOLEAN')] + [string]$format, + + [string]$field_values, + + [bool]$field_encrypted, + + [bool]$show_in_email, + + [string]$custom_format, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + if ($format -eq 'CUSTOM REGEX' -and (-not $custom_format)) { + throw "Please specify regex validation with -custom_format when using -format 'CUSTOM REGEX'" + } + + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + + $Body = $Values | ConvertTo-Json; + + } + + process{ + foreach($field_id in $id) { + $Parameters = @{ + Uri = "$url/api/v1/fields/$field_id" + Method = 'Put' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result + } + } +} + From 1b5e5e5237afdb4a9bc20955e2df385a19a5d7a5 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 13 Jun 2021 18:30:14 +0300 Subject: [PATCH 04/10] Remove-SnipeitAssetmaintenence --- SnipeitPS/Public/Remove-SnipeitAssetMaintenance.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SnipeitPS/Public/Remove-SnipeitAssetMaintenance.ps1 b/SnipeitPS/Public/Remove-SnipeitAssetMaintenance.ps1 index ed450f7..10cc017 100644 --- a/SnipeitPS/Public/Remove-SnipeitAssetMaintenance.ps1 +++ b/SnipeitPS/Public/Remove-SnipeitAssetMaintenance.ps1 @@ -2,10 +2,13 @@ function Remove-SnipeitAssetMaintenance { <# .SYNOPSIS Remove asset maintenance from Snipe-it asset system + .DESCRIPTION Removes asset maintenance event or events from Snipe-it asset system by ID + .PARAMETER ID Unique ID of the asset maintenance to be removed + .PARAMETER url URL of Snipeit system, can be set using Set-SnipeitInfoeItInfo command From dfb271dbec0b7aeab1fc8f53fb147ce7b5e11e4e Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 13 Jun 2021 18:32:42 +0300 Subject: [PATCH 05/10] set-snipeitcompany --- SnipeitPS/Public/Set-SnipeitCompany.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SnipeitPS/Public/Set-SnipeitCompany.ps1 b/SnipeitPS/Public/Set-SnipeitCompany.ps1 index 050e20c..4dcbb16 100644 --- a/SnipeitPS/Public/Set-SnipeitCompany.ps1 +++ b/SnipeitPS/Public/Set-SnipeitCompany.ps1 @@ -53,7 +53,7 @@ function Set-SnipeitCompany() process{ foreach($company_id in $id){ $Parameters = @{ - Uri = "$url/api/v1/companies/$companyid" + Uri = "$url/api/v1/companies/$company_id" Method = 'Patch' Body = $Body Token = $apiKey From 83eb3638895593a6feaef4fb8f8bbe67fe73b602 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 13 Jun 2021 18:35:43 +0300 Subject: [PATCH 06/10] set-snipeitcomponent --- SnipeitPS/Public/Set-SnipeitComponent.ps1 | 43 +++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/SnipeitPS/Public/Set-SnipeitComponent.ps1 b/SnipeitPS/Public/Set-SnipeitComponent.ps1 index e43466e..97115d9 100644 --- a/SnipeitPS/Public/Set-SnipeitComponent.ps1 +++ b/SnipeitPS/Public/Set-SnipeitComponent.ps1 @@ -49,8 +49,8 @@ function Set-SnipeitComponent() )] Param( - [parameter(mandatory = $true)] - [int]$id, + [parameter(mandatory = $true,ValueFromPipelineByPropertyName)] + [int[]]$id, [parameter(mandatory = $true)] [int]$qty, @@ -74,28 +74,33 @@ function Set-SnipeitComponent() [parameter(mandatory = $true)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + if ($values['purchase_date']) { + $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") + } - if ($values['purchase_date']) { - $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") + $Body = $values | ConvertTo-Json; } - $Body = $values | ConvertTo-Json; + process { + foreach($component_id in $id){ + $Parameters = @{ + Uri = "$url/api/v1/components/$component_id" + Method = 'Patch' + Body = $Body + Token = $apiKey + } - $Parameters = @{ - Uri = "$url/api/v1/components/$id" - Method = 'Patch' - Body = $Body - Token = $apiKey + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result + } } - - If ($PSCmdlet.ShouldProcess("ShouldProcess?")) - { - $result = Invoke-SnipeitMethod @Parameters - } - - $result } From cd86c6749d44188e44943e304a39799ae69dbfbe Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 13 Jun 2021 18:41:27 +0300 Subject: [PATCH 07/10] set and remove snipeitdepartment --- SnipeitPS/Public/Remove-SnipeitDepartment.ps1 | 2 +- SnipeitPS/Public/Set-SnipeitDepartment.ps1 | 85 +++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 SnipeitPS/Public/Set-SnipeitDepartment.ps1 diff --git a/SnipeitPS/Public/Remove-SnipeitDepartment.ps1 b/SnipeitPS/Public/Remove-SnipeitDepartment.ps1 index 7d0ed95..8bf9daa 100644 --- a/SnipeitPS/Public/Remove-SnipeitDepartment.ps1 +++ b/SnipeitPS/Public/Remove-SnipeitDepartment.ps1 @@ -37,7 +37,7 @@ function Remove-SnipeitDepartment () begin { } process { - foreach($depatment_id in $id){ + foreach($department_id in $id){ $Parameters = @{ Uri = "$url/api/v1/departments/$department_id" Method = 'Delete' diff --git a/SnipeitPS/Public/Set-SnipeitDepartment.ps1 b/SnipeitPS/Public/Set-SnipeitDepartment.ps1 new file mode 100644 index 0000000..8a66063 --- /dev/null +++ b/SnipeitPS/Public/Set-SnipeitDepartment.ps1 @@ -0,0 +1,85 @@ +<# + .SYNOPSIS + Updates a department + + .DESCRIPTION + Updates the department on Snipe-It system + + .PARAMETER id + Id number of Department + + .PARAMETER name + Department Name + + .PARAMETER company_id + ID number of company + + .PARAMETER location_id + ID number of location + + .PARAMETER manager_id + ID number of manager + + .PARAMETER url + URL of Snipeit system, can be set using Set-SnipeitInfo command + + .PARAMETER apiKey + Users API Key for Snipeit, can be set using Set-SnipeitInfo command + + .EXAMPLE + Set-SnipeitDepartment -id 4 -manager_id 3 + +#> + +function Set-SnipeitDepartment() { + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true,ValueFromPipelineByPropertyName)] + [int[]]$id, + + [string]$name, + + [int]$company_id, + + [int]$location_id, + + [int]$manager_id, + + [string]$notes, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + begin { + + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + + $Body = $Values | ConvertTo-Json; + } + + process { + foreach ($department_id in $id) { + $Parameters = @{ + Uri = "$url/api/v1/departments/$department_id" + Method = 'Put' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result + } + } +} + From 528367cbd65112d3a82ee0a75a7cb2be5814215e Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 13 Jun 2021 18:43:58 +0300 Subject: [PATCH 08/10] set-snipeitlicence --- SnipeitPS/Public/Set-SnipeitLicense.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SnipeitPS/Public/Set-SnipeitLicense.ps1 b/SnipeitPS/Public/Set-SnipeitLicense.ps1 index 3664841..9f1d1c7 100644 --- a/SnipeitPS/Public/Set-SnipeitLicense.ps1 +++ b/SnipeitPS/Public/Set-SnipeitLicense.ps1 @@ -129,6 +129,7 @@ function Set-SnipeitLicense() { [parameter(mandatory = $true)] [string]$apiKey ) + begin{ Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name @@ -148,6 +149,7 @@ function Set-SnipeitLicense() { $Body = $Values | ConvertTo-Json; } + process { foreach($license_id in $id){ $Parameters = @{ From e8d52ab59cbc1ba517eeb58c5f4c6240ec9828aa Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 13 Jun 2021 18:44:43 +0300 Subject: [PATCH 09/10] some formating --- SnipeitPS/Public/Set-SnipeitUser.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SnipeitPS/Public/Set-SnipeitUser.ps1 b/SnipeitPS/Public/Set-SnipeitUser.ps1 index e4cebd7..124acf7 100644 --- a/SnipeitPS/Public/Set-SnipeitUser.ps1 +++ b/SnipeitPS/Public/Set-SnipeitUser.ps1 @@ -80,13 +80,10 @@ function Set-SnipeitUser() { [string]$userName, - [string]$jobtitle, - [string]$email, - [string]$phone, [int]$company_id, @@ -97,12 +94,10 @@ function Set-SnipeitUser() { [int]$manager_id, - [string]$employee_num, [bool]$activated, - [string]$notes, [parameter(mandatory = $true)] From 3a0b1d853aeef68ad60c1c41912e368bd9c7e388 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Sun, 13 Jun 2021 18:54:12 +0300 Subject: [PATCH 10/10] set-snipeitstatus --- SnipeitPS/Public/Set-SnipeitStatus.ps1 | 83 ++++++++++++++++++++++++++ SnipeitPS/SnipeitPS.psd1 | 53 +++++++++------- 2 files changed, 113 insertions(+), 23 deletions(-) create mode 100644 SnipeitPS/Public/Set-SnipeitStatus.ps1 diff --git a/SnipeitPS/Public/Set-SnipeitStatus.ps1 b/SnipeitPS/Public/Set-SnipeitStatus.ps1 new file mode 100644 index 0000000..54ee8d8 --- /dev/null +++ b/SnipeitPS/Public/Set-SnipeitStatus.ps1 @@ -0,0 +1,83 @@ +<# +.SYNOPSIS +Sets Snipe-it Status Labels + +.PARAMETER id +A id of specific Status Label + + +.PARAMETER color +Hex code showing what color the status label should be on the pie chart in the dashboard + +.PARAMETER show_in_nav +1 or 0 - determine whether the status label should show in the left-side nav of the web GUI + +.PARAMETER default_label +1 or 0 - determine whether it should be bubbled up to the top of the list of available statuses + +.PARAMETER url +URL of Snipeit system, can be set using Set-SnipeitInfo command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-SnipeitInfo command + +.EXAMPLE +Get-SnipeitStatus -search "Ready to Deploy" + +.EXAMPLE +Set-SnipeitStatus -id 3 -name 'Waiting for arrival' -type pending + +#> + +function Set-SnipeitStatus() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Medium" + )] + Param( + [parameter(Mandatory=$true,ValueFromPipelineByPropertyName)] + [int[]]$id, + + [string]$name, + + [parameter(Mandatory=$true)] + [ValidateSet('deployable','undeployable','pending','archived')] + [string]$type, + + [string]$notes, + + [string]$color, + + [bool]$show_in_nav, + + [bool]$default_label, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + begin { + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $Body = $Values | ConvertTo-Json + } + + process { + foreach($status_id in $id) { + $Parameters = @{ + Uri = "$url/api/v1/statuslabels/$status_id" + Method = 'Put' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + $result + } + } +} diff --git a/SnipeitPS/SnipeitPS.psd1 b/SnipeitPS/SnipeitPS.psd1 index d9daa74..d24b9a9 100644 --- a/SnipeitPS/SnipeitPS.psd1 +++ b/SnipeitPS/SnipeitPS.psd1 @@ -70,6 +70,9 @@ PowerShellVersion = '3.0' # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. FunctionsToExport = @( + 'Get-SnipeitAccessory', + 'Get-SnipeitAccessoryOwner', + 'Get-SnipeitActivity', 'Get-SnipeitAsset', 'Get-SnipeitAssetMaintenance', 'Get-SnipeitCategory', @@ -78,45 +81,30 @@ FunctionsToExport = @( 'Get-SnipeitCustomField', 'Get-SnipeitDepartment', 'Get-SnipeitFieldset', + 'Get-SnipeitLicense', + 'Get-SnipeitLicenseSeat', 'Get-SnipeitLocation', 'Get-SnipeitManufacturer', 'Get-SnipeitModel', 'Get-SnipeitStatus', 'Get-SnipeitSupplier', 'Get-SnipeitUser', + 'New-SnipeitAccessory', 'New-SnipeitAsset', 'New-SnipeitAssetMaintenance', + 'New-SnipeItAudit', 'New-SnipeitCategory', 'New-SnipeitComponent', 'New-SnipeitCustomField', 'New-SnipeitDepartment', 'New-SnipeitLicense', - 'Set-SnipeitLicense', - 'Get-SnipeitLicense', - 'Get-SnipeitLicenseSeat', - 'Set-SnipeitLicenseSeat', 'New-SnipeitLocation', 'New-SnipeitManufacturer', 'New-SnipeitModel', 'New-SnipeitUser', - 'Set-SnipeitAsset', - 'Set-SnipeitAssetOwner', - 'Set-SnipeitComponent', - 'Set-SnipeitModel', - 'Set-SnipeitInfo', - 'Set-SnipeitUser', - 'Set-SnipeitLocation', - 'Add-SnipeitAccessory', - 'Set-SnipeitAccessory', - 'Get-SnipeitAccessory', - 'Remove-SnipeitAsset', - 'Remove-SnipeitUser', - 'Update-SnipeitAlias', - 'Set-SnipeitAccessoryOwner', - 'Get-SnipeitAccessoryOwner', - 'Reset-SnipeitAccessoryOwner', - 'Get-SnipeitActivity', 'Remove-SnipeitAccessory', + 'Remove-SnipeitAsset', + 'Remove-SnipeitAssetMaintenance', 'Remove-SnipeitCategory', 'Remove-SnipeitCompany', 'Remove-SnipeitComponent', @@ -125,8 +113,27 @@ FunctionsToExport = @( 'Remove-SnipeitLicense', 'Remove-SnipeitLocation', 'Remove-SnipeitManufacturer', - 'Remove-SnipeitModel' - + 'Remove-SnipeitModel', + 'Remove-SnipeitUser', + 'Reset-SnipeitAccessoryOwner', + 'Reset-SnipeitAssetOwner', + 'Set-SnipeitAccessory', + 'Set-SnipeitAccessoryOwner', + 'Set-SnipeitAsset', + 'Set-SnipeitAssetOwner', + 'Set-SnipeitCategory' + 'Set-SnipeitCompany' + 'Set-SnipeitComponent', + 'Set-SnipeitCustomField', + 'Set-SnipeitDepartment', + 'Set-SnipeitInfo', + 'Set-SnipeitLicense', + 'Set-SnipeitLicenseSeat', + 'Set-SnipeitLocation', + 'Set-SnipeitModel', + 'Set-SnipeitStatus', + 'Set-SnipeitUser', + 'Update-SnipeitAlias' ) # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.