From f175d339515519aba868087e318b56ab5d3e1763 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 25 Jun 2018 16:06:35 +0200 Subject: [PATCH 1/5] Added Get-CustomField --- SnipeitPS/Public/Get-CustomField.ps1 | 35 +++++++++++++++++++++++++++ SnipeitPS/SnipeItPS.psd1 | Bin 9124 -> 9180 bytes 2 files changed, 35 insertions(+) create mode 100644 SnipeitPS/Public/Get-CustomField.ps1 diff --git a/SnipeitPS/Public/Get-CustomField.ps1 b/SnipeitPS/Public/Get-CustomField.ps1 new file mode 100644 index 0000000..8a26143 --- /dev/null +++ b/SnipeitPS/Public/Get-CustomField.ps1 @@ -0,0 +1,35 @@ +<# +.SYNOPSIS +# Returns a list of all Snipe-IT custom fields + +.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-Field -url "https://assets.example.com" -token "token..." + +#> + +function Get-CustomField() +{ + Param( + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/fields" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-SnipeitMethod @Parameters + + $result +} diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 7a5e4a3b704d0a42a24a704e1f97a779ff1aa97c..7bd75c476e2b723ba8e9962fc6c9353c16e63930 100644 GIT binary patch delta 42 xcmZ4De#d=7m58V_Ln%WsLkUAZLoS0GLncEiLk>gAWJ6Ku$p*q4o2x{$_yGp^3k?7O delta 12 TcmccPzQlb)mB{8zB3k?aCWHk4 From b61f89fee2c18ce22321e41c0cdc5753872becf7 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 25 Jun 2018 16:06:58 +0200 Subject: [PATCH 2/5] Added Get-FieldSet --- SnipeitPS/Public/Get-Fieldset.ps1 | 37 ++++++++++++++++++++++++++++++ SnipeitPS/SnipeItPS.psd1 | Bin 9180 -> 9230 bytes 2 files changed, 37 insertions(+) create mode 100644 SnipeitPS/Public/Get-Fieldset.ps1 diff --git a/SnipeitPS/Public/Get-Fieldset.ps1 b/SnipeitPS/Public/Get-Fieldset.ps1 new file mode 100644 index 0000000..9e4058d --- /dev/null +++ b/SnipeitPS/Public/Get-Fieldset.ps1 @@ -0,0 +1,37 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Fieldsets + +.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-Fieldset -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Fieldset -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Windows" } + +#> + +function Get-Fieldset() { + Param( + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/fieldsets" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-SnipeitMethod @Parameters + + $result +} diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 7bd75c476e2b723ba8e9962fc6c9353c16e63930..f100983f6a8f0b3e18708f0b266fd55049d02fd2 100644 GIT binary patch delta 34 qcmccP-siF5l<;H&VGd3=hD?T3h8%{J$&Esalg|lpY`!GSB>(`* Date: Mon, 25 Jun 2018 16:07:47 +0200 Subject: [PATCH 3/5] Added New-CustomField --- SnipeitPS/Public/New-CustomField.ps1 | 72 +++++++++++++++++++++++++++ SnipeitPS/SnipeItPS.psd1 | Bin 9230 -> 9286 bytes 2 files changed, 72 insertions(+) create mode 100644 SnipeitPS/Public/New-CustomField.ps1 diff --git a/SnipeitPS/Public/New-CustomField.ps1 b/SnipeitPS/Public/New-CustomField.ps1 new file mode 100644 index 0000000..2fe0482 --- /dev/null +++ b/SnipeitPS/Public/New-CustomField.ps1 @@ -0,0 +1,72 @@ +<# + .SYNOPSIS + Add a new Custom Field to Snipe-it asset system + + .DESCRIPTION + Add a new Custom Field to Snipe-it asset system + + .PARAMETER Name + Name of the Custom Field + + .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 + New-Field -Name "AntivirusInstalled" -Format "BOOLEAN" -HelpText "Is AntiVirus installed on Asset" +#> + +function New-CustomField() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [string]$Name, + + [string]$HelpText, + + [string]$Element = "text", + + [string]$Format = "ANY", + + [string]$CustomFormat, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + + $Values = @{ + "name" = $Name + "help_text" = $HelpText + "element" = $Element + "format" = $Format + "custom_format" = $CustomFormat + } + + #Convert Values to JSON format + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/fields" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index f100983f6a8f0b3e18708f0b266fd55049d02fd2..91d74293a1d3393927f6b733b888d77f9cfa12ea 100644 GIT binary patch delta 192 zcmeD4IOefok7E2S=n=B+|G%^?U>?UE0$$cU!Kt9*xLt;u`bJmC}0p++R?-9|NEF}sSV-95~ zo*XDH54Q6SP~8I&tI4~B^}u{NF+GU6Vn&lg#31&`2^&nV6XKd&C29e5qtfOF;%Php Dt9(Di From 1ec8bf1b13374b40bfd72789e4f067bb0ad30d6f Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Fri, 26 Apr 2019 16:30:00 +0100 Subject: [PATCH 4/5] Fixed #22 #20 #18 #16 --- SnipeitPS/Private/ConvertTo-GetParameter.ps1 | 4 +- SnipeitPS/Public/New-AssetMaintenance.ps1 | 12 +-- SnipeitPS/Public/New-Model.ps1 | 7 ++ SnipeitPS/Public/Set-Model.ps1 | 90 +++++++++++++++++++ SnipeitPS/SnipeItPS.psd1 | Bin 9286 -> 9330 bytes SnipeitPS/SnipeItPS.psm1 | 4 +- 6 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 SnipeitPS/Public/Set-Model.ps1 diff --git a/SnipeitPS/Private/ConvertTo-GetParameter.ps1 b/SnipeitPS/Private/ConvertTo-GetParameter.ps1 index e0f31c9..6cee2f0 100644 --- a/SnipeitPS/Private/ConvertTo-GetParameter.ps1 +++ b/SnipeitPS/Private/ConvertTo-GetParameter.ps1 @@ -16,11 +16,11 @@ function ConvertTo-GetParameter { PROCESS { Write-Verbose "[$($MyInvocation.MyCommand.Name)] Making HTTP get parameter string out of a hashtable" foreach ($key in $InputObject.Keys) { - $parameters += "$key=$($InputObject[$key])&" + $parameters += "$key=$([System.Web.HttpUtility]::UrlEncode($InputObject[$key]))&" } } END { $parameters -replace ".$" } -} \ No newline at end of file +} diff --git a/SnipeitPS/Public/New-AssetMaintenance.ps1 b/SnipeitPS/Public/New-AssetMaintenance.ps1 index f49b7dd..f5c6539 100644 --- a/SnipeitPS/Public/New-AssetMaintenance.ps1 +++ b/SnipeitPS/Public/New-AssetMaintenance.ps1 @@ -53,12 +53,12 @@ function New-AssetMaintenance() { [string]$title, [parameter(mandatory = $true)] - [string]$startDate, + [datetime]$startDate, [parameter(mandatory = $false)] - [string]$completionDate, + [datetime]$completionDate, - [switch]$is_warranty = $false, + [switch]$is_warranty=$false, [decimal]$cost, @@ -76,11 +76,11 @@ function New-AssetMaintenance() { "supplier_id" = $supplier_id "asset_maintenance_type" = $asset_maintenance_type "title" = $title - "start_date" = $startDate - "is_warranty" = $is_warranty + "start_date" = $startDate.ToString("yyyy-MM-dd") + "is_warranty" = [Bool]::Parse($is_warranty) } - if ($PSBoundParameters.ContainsKey('completionDate')) { $Values.Add("completion_date", $completionDate) } + if ($PSBoundParameters.ContainsKey('completionDate')) { $Values.Add("completion_date", $completionDate.ToString("yyyy-MM-dd")) } if ($PSBoundParameters.ContainsKey('cost')) { $Values.Add("cost", $cost) } if ($PSBoundParameters.ContainsKey('notes')) { $Values.Add("notes", $notes) } diff --git a/SnipeitPS/Public/New-Model.ps1 b/SnipeitPS/Public/New-Model.ps1 index af21b76..239a6b9 100644 --- a/SnipeitPS/Public/New-Model.ps1 +++ b/SnipeitPS/Public/New-Model.ps1 @@ -38,12 +38,16 @@ function New-Model() [parameter(mandatory = $true)] [string]$name, + [string]$model_number, + [parameter(mandatory = $true)] [int]$category_id, [parameter(mandatory = $true)] [int]$manufacturer_id, + [int]$eol, + [parameter(mandatory = $true)] [int]$fieldset_id, @@ -61,6 +65,9 @@ function New-Model() fieldset_id = $fieldset_id } + if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) } + if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) } + $Body = $Values | ConvertTo-Json; $Parameters = @{ diff --git a/SnipeitPS/Public/Set-Model.ps1 b/SnipeitPS/Public/Set-Model.ps1 new file mode 100644 index 0000000..de372a5 --- /dev/null +++ b/SnipeitPS/Public/Set-Model.ps1 @@ -0,0 +1,90 @@ +<# + .SYNOPSIS + Updates a Model within the Snipe-it asset system + + .DESCRIPTION + Long description + + .PARAMETER name + Name of the Asset Model + + .PARAMETER model_number + Part or model number of the model + + .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 eol + Number of months until this model's assets are considered EOL + + .PARAMETER fieldset_id + Fieldset ID that the asset uses (Custom fields) + + .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 + New-Model -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1 +#> + +function Set-Model() { + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Medium" + )] + + Param( + [parameter(mandatory = $true)] + [string]$name, + + [string]$model_number, + + [parameter(mandatory = $true)] + [int]$category_id, + + [parameter(mandatory = $true)] + [int]$manufacturer_id, + + [int]$eol, + + [parameter(mandatory = $true)] + [int]$fieldset_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + name = $name + category_id = $category_id + manufacturer_id = $manufacturer_id + fieldset_id = $fieldset_id + } + + if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) } + if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/models" + 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 91d74293a1d3393927f6b733b888d77f9cfa12ea..fa60caeedbdfac1a65945525035def9aa4501a49 100644 GIT binary patch delta 20 ccmX@+@yTPu8u7^o#8f61h;wXSBR-1<0A&XVhX4Qo delta 12 Ucmez5am-`G8u86H#AopU04w4K1ONa4 diff --git a/SnipeitPS/SnipeItPS.psm1 b/SnipeitPS/SnipeItPS.psm1 index 2290ad8..3450cae 100644 --- a/SnipeitPS/SnipeItPS.psm1 +++ b/SnipeitPS/SnipeItPS.psm1 @@ -1,10 +1,10 @@ -$scriptRoot = $PSScriptRoot + '\public' +$scriptRoot = $PSScriptRoot + '\Public' Get-ChildItem $scriptRoot *.ps1 | ForEach-Object { Import-Module $_.FullName } -$scriptRoot = $PSScriptRoot + '\private' +$scriptRoot = $PSScriptRoot + '\Private' Get-ChildItem $scriptRoot *.ps1 | ForEach-Object { Import-Module $_.FullName From 4f228333425ce81c65115c54818a7bf38e93a411 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 27 Apr 2019 09:51:49 +0100 Subject: [PATCH 5/5] Added donation link --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 2b5ce8e..d83949e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ --- +## Want to say thanks? + +[![paypal](https://www.paypalobjects.com/en_US/GB/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XP29MAD7P3WDN&source=url) + ## Instructions ### Installation