From 56852d863e6a38f75f60e483f353c2d156c5734a Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 27 Apr 2019 20:39:05 +0100 Subject: [PATCH] Added more commands and changed way parameters work, also added more parameters to bring it inline with recent api changed --- SnipeitPS/Private/ConvertTo-GetParameter.ps1 | 3 + SnipeitPS/Private/Get-ParameterValue.ps1 | 59 ++++++++++++ SnipeitPS/Public/Get-Accessory.ps1 | 47 ++++++++++ SnipeitPS/Public/Get-Asset.ps1 | 27 ++---- SnipeitPS/Public/Get-AssetMaintenance.ps1 | 10 +-- SnipeitPS/Public/Get-Category.ps1 | 9 +- SnipeitPS/Public/Get-Company.ps1 | 9 +- SnipeitPS/Public/Get-Component.ps1 | 16 ++-- SnipeitPS/Public/Get-Department.ps1 | 12 +-- SnipeitPS/Public/Get-License.ps1 | 26 ++---- SnipeitPS/Public/Get-Location.ps1 | 9 +- SnipeitPS/Public/Get-Manufacturer.ps1 | 9 +- SnipeitPS/Public/Get-Model.ps1 | 9 +- SnipeitPS/Public/Get-Status.ps1 | 9 +- SnipeitPS/Public/Get-Supplier.ps1 | 9 +- SnipeitPS/Public/Get-User.ps1 | 13 +-- SnipeitPS/Public/New-Accessory.ps1 | 65 ++++++++++++++ SnipeitPS/Public/New-AssetMaintenance.ps1 | 19 ++-- SnipeitPS/Public/New-Company.ps1 | 4 +- SnipeitPS/Public/New-Component.ps1 | 24 +++-- SnipeitPS/Public/New-CustomField.ps1 | 11 +-- SnipeitPS/Public/New-Department.ps1 | 21 ++--- SnipeitPS/Public/New-License.ps1 | 88 ++++++++++++++++++ SnipeitPS/Public/New-Location.ps1 | 13 ++- SnipeitPS/Public/Set-Accessory.ps1 | 65 ++++++++++++++ SnipeitPS/Public/Set-License.ps1 | 90 +++++++++++++++++++ SnipeitPS/Public/Set-Model.ps1 | 58 ++---------- SnipeitPS/SnipeItPS.psd1 | Bin 9330 -> 9582 bytes 28 files changed, 501 insertions(+), 233 deletions(-) create mode 100644 SnipeitPS/Private/Get-ParameterValue.ps1 create mode 100644 SnipeitPS/Public/Get-Accessory.ps1 create mode 100644 SnipeitPS/Public/New-Accessory.ps1 create mode 100644 SnipeitPS/Public/New-License.ps1 create mode 100644 SnipeitPS/Public/Set-Accessory.ps1 create mode 100644 SnipeitPS/Public/Set-License.ps1 diff --git a/SnipeitPS/Private/ConvertTo-GetParameter.ps1 b/SnipeitPS/Private/ConvertTo-GetParameter.ps1 index 6cee2f0..a3065a4 100644 --- a/SnipeitPS/Private/ConvertTo-GetParameter.ps1 +++ b/SnipeitPS/Private/ConvertTo-GetParameter.ps1 @@ -1,4 +1,5 @@ function ConvertTo-GetParameter { + <# .SYNOPSIS Generate the GET parameter string for an URL from a hashtable @@ -14,6 +15,8 @@ function ConvertTo-GetParameter { } PROCESS { + Add-Type -AssemblyName System.Web + Write-Verbose "[$($MyInvocation.MyCommand.Name)] Making HTTP get parameter string out of a hashtable" foreach ($key in $InputObject.Keys) { $parameters += "$key=$([System.Web.HttpUtility]::UrlEncode($InputObject[$key]))&" diff --git a/SnipeitPS/Private/Get-ParameterValue.ps1 b/SnipeitPS/Private/Get-ParameterValue.ps1 new file mode 100644 index 0000000..f8f7882 --- /dev/null +++ b/SnipeitPS/Private/Get-ParameterValue.ps1 @@ -0,0 +1,59 @@ +function Get-ParameterValue { + #.Synopsis + # Get the actual values of parameters which have manually set (non-null) default values or values passed in the call + #.Description + # Unlike $PSBoundParameters, the hashtable returned from Get-ParameterValues includes non-empty default parameter values. + # NOTE: Default values that are the same as the implied values are ignored (e.g.: empty strings, zero numbers, nulls). + #.Example + # function Test-Parameters { + # [CmdletBinding()] + # param( + # $Name = $Env:UserName, + # $Age + # ) + # $Parameters = . Get-ParameterValues + # + # # This WILL ALWAYS have a value... + # Write-Host $Parameters["Name"] + # + # # But this will NOT always have a value... + # Write-Host $PSBoundParameters["Name"] + # } + [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, + + [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" + } + + $ParameterValues = @{} + foreach ($parameter in $Invocation.MyCommand.Parameters.GetEnumerator()) { + # gm -in $parameter.Value | Out-Default + try { + $key = $parameter.Key + if ($key -notin $DefaultExcludeParameter) { + if ($null -ne ($value = Get-Variable -Name $key -ValueOnly -ErrorAction Ignore )) { + if ($value -ne ($null -as $parameter.Value.ParameterType)) { + $ParameterValues[$key] = $value + } + } + + if ($BoundParameters.ContainsKey($key)) { + $ParameterValues[$key] = $BoundParameters[$key] + } + } + } + finally {} + } + return $ParameterValues +} diff --git a/SnipeitPS/Public/Get-Accessory.ps1 b/SnipeitPS/Public/Get-Accessory.ps1 new file mode 100644 index 0000000..d820eea --- /dev/null +++ b/SnipeitPS/Public/Get-Accessory.ps1 @@ -0,0 +1,47 @@ +function Get-Accessory() { + Param( + [string]$search, + + [int]$company_id, + + [int]$category_id, + + [int]$manufacturer_id, + + [int]$supplier_id, + + [string]$sort = "created_at", + + [ValidateSet("asc", "desc")] + [string]$order = "desc", + + [int]$limit = 50, + + [int]$offset, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $SearchParameter = . Get-ParameterValue + + $Parameters = @{ + Uri = "$url/api/v1/accessories" + Method = 'Get' + GetParameters = $SearchParameter + Token = $apiKey + } + + $result = Invoke-SnipeitMethod @Parameters + + $result +} + + + + + + diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 018da35..ab1f4f4 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -51,7 +51,10 @@ Users API Key for Snipeit, can be set using Set-Info command Get-Asset -url "https://assets.example.com" -token "token..." .EXAMPLE -Get-Asset -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "MyMachine" } +Get-Asset -search "myMachine" -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Asset -search "myMachine" -url "https://assets.example.com" -token "token..." #> function Get-Asset() { Param( @@ -69,6 +72,10 @@ function Get-Asset() { [int]$location_id, + [int]$depreciation_id, + + [bool]$requestable = $false, + [string]$status, [int]$status_id, @@ -89,23 +96,7 @@ function Get-Asset() { [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } - if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) } - if ($PSBoundParameters.ContainsKey('model_id')) { $SearchParameter.Add("model_id", $model_id) } - if ($PSBoundParameters.ContainsKey('category_id')) { $SearchParameter.Add("category_id", $category_id) } - if ($PSBoundParameters.ContainsKey('manufacturer_id')) { $SearchParameter.Add("manufacturer_id", $manufacturer_id) } - if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) } - if ($PSBoundParameters.ContainsKey('location_id')) { $SearchParameter.Add("location_id", $location_id) } - if ($PSBoundParameters.ContainsKey('status_id')) { $SearchParameter.Add("status_id", $order_number) } - if ($PSBoundParameters.ContainsKey('status')) { $SearchParameter.Add("status", $order_number) } - if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/hardware" diff --git a/SnipeitPS/Public/Get-AssetMaintenance.ps1 b/SnipeitPS/Public/Get-AssetMaintenance.ps1 index 32d0c5c..4828474 100644 --- a/SnipeitPS/Public/Get-AssetMaintenance.ps1 +++ b/SnipeitPS/Public/Get-AssetMaintenance.ps1 @@ -57,15 +57,7 @@ function Get-AssetMaintenance() { [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } - if ($PSBoundParameters.ContainsKey('asset_id')) { $SearchParameter.Add("asset_id", $asset_id) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/maintenances" diff --git a/SnipeitPS/Public/Get-Category.ps1 b/SnipeitPS/Public/Get-Category.ps1 index 391b9a9..0c697c9 100644 --- a/SnipeitPS/Public/Get-Category.ps1 +++ b/SnipeitPS/Public/Get-Category.ps1 @@ -35,14 +35,7 @@ function Get-Category() [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/categories" diff --git a/SnipeitPS/Public/Get-Company.ps1 b/SnipeitPS/Public/Get-Company.ps1 index 46860c2..1f20ba2 100644 --- a/SnipeitPS/Public/Get-Company.ps1 +++ b/SnipeitPS/Public/Get-Company.ps1 @@ -35,14 +35,7 @@ function Get-Company() [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/companies" diff --git a/SnipeitPS/Public/Get-Component.ps1 b/SnipeitPS/Public/Get-Component.ps1 index 39c14e9..e55616d 100644 --- a/SnipeitPS/Public/Get-Component.ps1 +++ b/SnipeitPS/Public/Get-Component.ps1 @@ -24,9 +24,14 @@ function Get-Component() { [int]$company_id, + [int]$location_id, + [ValidateSet("asc", "desc")] [string]$order = "desc", + [ValidateSet('id', 'name', 'min_amt', 'order_number', 'serial', 'purchase_date', 'purchase_cost', 'company', 'category', 'qty', 'location', 'image', 'created_at')] + [string]$sort = "created_at", + [int]$limit = 50, [int]$offset, @@ -38,16 +43,7 @@ function Get-Component() { [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } - if ($PSBoundParameters.ContainsKey('category_id')) { $SearchParameter.Add("category_id", $category_id) } - if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/components" diff --git a/SnipeitPS/Public/Get-Department.ps1 b/SnipeitPS/Public/Get-Department.ps1 index eeec2a2..840409e 100644 --- a/SnipeitPS/Public/Get-Department.ps1 +++ b/SnipeitPS/Public/Get-Department.ps1 @@ -28,6 +28,9 @@ function Get-Department() [int]$offset, + [ValidateSet('id', 'name', 'image', 'users_count', 'created_at')] + [string]$sort = "created_at", + [parameter(mandatory = $true)] [string]$url, @@ -35,14 +38,7 @@ function Get-Department() [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/departments" diff --git a/SnipeitPS/Public/Get-License.ps1 b/SnipeitPS/Public/Get-License.ps1 index 2adb5a4..fccb45e 100644 --- a/SnipeitPS/Public/Get-License.ps1 +++ b/SnipeitPS/Public/Get-License.ps1 @@ -32,7 +32,7 @@ function Get-License() { [string]$license_name, - [string]$license_email, + [mailaddress]$license_email, [int]$manufacturer_id, @@ -40,9 +40,14 @@ function Get-License() { [int]$depreciation_id, + [int]$category_id, + [ValidateSet("asc", "desc")] [string]$order = "desc", + [ValidateSet('id', 'name', 'purchase_cost', 'expiration_date', 'purchase_order', 'order_number', 'notes', 'purchase_date', 'serial', 'company', 'category', 'license_name', 'license_email', 'free_seats_count', 'seats', 'manufacturer', 'supplier')] + [string]$sort = "created_at", + [int]$limit = 50, [int]$offset, @@ -54,24 +59,7 @@ function Get-License() { [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } - if ($PSBoundParameters.ContainsKey('name')) { $SearchParameter.Add("name", $name) } - if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) } - if ($PSBoundParameters.ContainsKey('product_key')) { $SearchParameter.Add("product_key", $product_key) } - if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) } - if ($PSBoundParameters.ContainsKey('purchase_order')) { $SearchParameter.Add("purchase_order", $purchase_order) } - if ($PSBoundParameters.ContainsKey('license_name')) { $SearchParameter.Add("license_name", $license_name) } - if ($PSBoundParameters.ContainsKey('license_email')) { $SearchParameter.Add("license_email", $license_email) } - if ($PSBoundParameters.ContainsKey('manufacturer_id')) { $SearchParameter.Add("manufacturer_id", $manufacturer_id) } - if ($PSBoundParameters.ContainsKey('supplier_id')) { $SearchParameter.Add("supplier_id", $supplier_id) } - if ($PSBoundParameters.ContainsKey('depreciation_id')) { $SearchParameter.Add("depreciation_id", $depreciation_id) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/licenses" diff --git a/SnipeitPS/Public/Get-Location.ps1 b/SnipeitPS/Public/Get-Location.ps1 index f4090e8..3fb46cf 100644 --- a/SnipeitPS/Public/Get-Location.ps1 +++ b/SnipeitPS/Public/Get-Location.ps1 @@ -35,14 +35,7 @@ function Get-Location() [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/locations" diff --git a/SnipeitPS/Public/Get-Manufacturer.ps1 b/SnipeitPS/Public/Get-Manufacturer.ps1 index cf07026..b55798e 100644 --- a/SnipeitPS/Public/Get-Manufacturer.ps1 +++ b/SnipeitPS/Public/Get-Manufacturer.ps1 @@ -35,14 +35,7 @@ function Get-Manufacturer() [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/manufacturers" diff --git a/SnipeitPS/Public/Get-Model.ps1 b/SnipeitPS/Public/Get-Model.ps1 index 8b2b581..c15d7c7 100644 --- a/SnipeitPS/Public/Get-Model.ps1 +++ b/SnipeitPS/Public/Get-Model.ps1 @@ -35,14 +35,7 @@ function Get-Model() [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/models" diff --git a/SnipeitPS/Public/Get-Status.ps1 b/SnipeitPS/Public/Get-Status.ps1 index 4b3eea5..a5f4f89 100644 --- a/SnipeitPS/Public/Get-Status.ps1 +++ b/SnipeitPS/Public/Get-Status.ps1 @@ -35,14 +35,7 @@ function Get-Status() [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/statuslabels" diff --git a/SnipeitPS/Public/Get-Supplier.ps1 b/SnipeitPS/Public/Get-Supplier.ps1 index 91a5dd2..f556cd4 100644 --- a/SnipeitPS/Public/Get-Supplier.ps1 +++ b/SnipeitPS/Public/Get-Supplier.ps1 @@ -35,14 +35,7 @@ function Get-Supplier() [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/suppliers" diff --git a/SnipeitPS/Public/Get-User.ps1 b/SnipeitPS/Public/Get-User.ps1 index 3cd71d1..00132fd 100644 --- a/SnipeitPS/Public/Get-User.ps1 +++ b/SnipeitPS/Public/Get-User.ps1 @@ -41,18 +41,7 @@ function Get-User() { [string]$apiKey ) - $SearchParameter = @{ - sort = $sort - order = $order - limit = $limit - offset = $offset - } - - if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) } - if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) } - if ($PSBoundParameters.ContainsKey('location_id')) { $SearchParameter.Add("location_id", $location_id) } - if ($PSBoundParameters.ContainsKey('group_id')) { $SearchParameter.Add("group_id", $group_id) } - if ($PSBoundParameters.ContainsKey('department_id')) { $SearchParameter.Add("department_id", $department_id) } + $SearchParameter = . Get-ParameterValue $Parameters = @{ Uri = "$url/api/v1/users" diff --git a/SnipeitPS/Public/New-Accessory.ps1 b/SnipeitPS/Public/New-Accessory.ps1 new file mode 100644 index 0000000..46e3849 --- /dev/null +++ b/SnipeitPS/Public/New-Accessory.ps1 @@ -0,0 +1,65 @@ + +function New-Accessory() { + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [ValidateLength(3, 255)] + [string]$name, + + [parameter(mandatory = $true)] + [int]$qty, + + [parameter(mandatory = $true)] + [ValidateRange(1, [int]::MaxValue)] + [int]$category_id, + + [ValidateRange(1, [int]::MaxValue)] + [int]$company_id, + + [ValidateRange(1, [int]::MaxValue)] + [int]$manufacturer_id, + + [string]$order_number, + + [float]$purchase_cost, + + [datetime]$purchase_date, + + [bool]$requestable, + + [ValidateRange(1, [int]::MaxValue)] + [int]$supplier_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = . Get-ParameterValue + + if ($values['purchase_date']) { + $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/accessories" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} + diff --git a/SnipeitPS/Public/New-AssetMaintenance.ps1 b/SnipeitPS/Public/New-AssetMaintenance.ps1 index f5c6539..87e0f51 100644 --- a/SnipeitPS/Public/New-AssetMaintenance.ps1 +++ b/SnipeitPS/Public/New-AssetMaintenance.ps1 @@ -58,7 +58,7 @@ function New-AssetMaintenance() { [parameter(mandatory = $false)] [datetime]$completionDate, - [switch]$is_warranty=$false, + [bool]$is_warranty = $false, [decimal]$cost, @@ -71,18 +71,15 @@ function New-AssetMaintenance() { [string]$apiKey ) - $Values = @{ - "asset_id" = $asset_id - "supplier_id" = $supplier_id - "asset_maintenance_type" = $asset_maintenance_type - "title" = $title - "start_date" = $startDate.ToString("yyyy-MM-dd") - "is_warranty" = [Bool]::Parse($is_warranty) + $Values = . Get-ParameterValue + + if ($values['start_date']) { + $values['start_date'] = $values['start_date'].ToString("yyyy-MM-dd") } - 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) } + if ($values['completionDate']) { + $values['completionDate'] = $values['completionDate'].ToString("yyyy-MM-dd") + } $Body = $Values | ConvertTo-Json; diff --git a/SnipeitPS/Public/New-Company.ps1 b/SnipeitPS/Public/New-Company.ps1 index aa3d2e5..56aa590 100644 --- a/SnipeitPS/Public/New-Company.ps1 +++ b/SnipeitPS/Public/New-Company.ps1 @@ -39,9 +39,7 @@ function New-Company() [string]$apiKey ) - $Values = @{ - "name" = $name - } + $Values = . Get-ParameterValue $Body = $Values | ConvertTo-Json; diff --git a/SnipeitPS/Public/New-Component.ps1 b/SnipeitPS/Public/New-Component.ps1 index 690b1c8..f07534c 100644 --- a/SnipeitPS/Public/New-Component.ps1 +++ b/SnipeitPS/Public/New-Component.ps1 @@ -27,8 +27,7 @@ General notes #> -function New-Component() -{ +function New-Component() { [CmdletBinding( SupportsShouldProcess = $true, ConfirmImpact = "Low" @@ -39,11 +38,19 @@ function New-Component() [string]$name, [parameter(mandatory = $true)] - [string]$category_id, + [int]$category_id, [parameter(mandatory = $true)] [string]$qty, + [int]$company_id, + + [int]$location_id, + + [datetime]$purchase_date, + + [float]$purchase_cost, + [parameter(mandatory = $true)] [string]$url, @@ -51,10 +58,10 @@ function New-Component() [string]$apiKey ) - $Values = @{ - "name" = $name - "category_id" = $category_id - "qty" = $qty + $Values = . Get-ParameterValue + + if ($values['purchase_date']) { + $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") } $Body = $Values | ConvertTo-Json; @@ -66,8 +73,7 @@ function New-Component() Token = $apiKey } - If ($PSCmdlet.ShouldProcess("ShouldProcess?")) - { + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-SnipeitMethod @Parameters } diff --git a/SnipeitPS/Public/New-CustomField.ps1 b/SnipeitPS/Public/New-CustomField.ps1 index 2fe0482..bd93f6b 100644 --- a/SnipeitPS/Public/New-CustomField.ps1 +++ b/SnipeitPS/Public/New-CustomField.ps1 @@ -35,6 +35,8 @@ function New-CustomField() [string]$Format = "ANY", + [bool]$field_encrypted, + [string]$CustomFormat, [parameter(mandatory = $true)] @@ -44,14 +46,7 @@ function New-CustomField() [string]$apiKey ) - - $Values = @{ - "name" = $Name - "help_text" = $HelpText - "element" = $Element - "format" = $Format - "custom_format" = $CustomFormat - } + $Values = . Get-ParameterValue #Convert Values to JSON format $Body = $Values | ConvertTo-Json; diff --git a/SnipeitPS/Public/New-Department.ps1 b/SnipeitPS/Public/New-Department.ps1 index 0fe2536..867c0dc 100644 --- a/SnipeitPS/Public/New-Department.ps1 +++ b/SnipeitPS/Public/New-Department.ps1 @@ -27,8 +27,7 @@ General notes #> -function New-Department() -{ +function New-Department() { [CmdletBinding( SupportsShouldProcess = $true, ConfirmImpact = "Low" @@ -38,11 +37,13 @@ function New-Department() [parameter(mandatory = $true)] [string]$name, - [string]$company_id, + [int]$company_id, - [string]$location_id, + [int]$location_id, - [string]$manager_id, + [int]$manager_id, + + [string]$notes, [parameter(mandatory = $true)] [string]$url, @@ -51,12 +52,7 @@ function New-Department() [string]$apiKey ) - $Values = @{ - "name" = $name - "company_id" = $company_id - "location_id" = $location_id - "manager_id" = $manager_id - } + $Values = . Get-ParameterValue $Body = $Values | ConvertTo-Json; @@ -67,8 +63,7 @@ function New-Department() Token = $apiKey } - If ($PSCmdlet.ShouldProcess("ShouldProcess?")) - { + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-SnipeitMethod @Parameters } diff --git a/SnipeitPS/Public/New-License.ps1 b/SnipeitPS/Public/New-License.ps1 new file mode 100644 index 0000000..44c24d4 --- /dev/null +++ b/SnipeitPS/Public/New-License.ps1 @@ -0,0 +1,88 @@ + +function New-License() { + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [ValidateLength(3, 255)] + [string]$name, + + [parameter(mandatory = $true)] + [int]$seats, + + [ValidateRange(1, [int]::MaxValue)] + [int]$category_id, + + [ValidateRange(1, [int]::MaxValue)] + [int]$company_id, + + [datetime]$expiration_date, + + [ValidateLength(1, 120)] + [mailaddress]$license_email, + + [ValidateLength(1, 100)] + [string]$license_name, + + [bool]$maintained, + + [ValidateRange(1, [int]::MaxValue)] + [int]$manufacturer_id, + + [string]$notes, + + [string]$order_number, + + [float]$purchase_cost, + + [datetime]$purchase_date, + + [bool]$reassignable, + + [string]$serial, + + [ValidateRange(1, [int]::MaxValue)] + [int]$supplier_id, + + [datetime]$termination_date, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = . Get-ParameterValue + + if ($values['expiration_date']) { + $values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd") + } + + if ($values['purchase_date']) { + $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") + } + + if ($values['termination_date']) { + $values['termination_date'] = $values['termination_date'].ToString("yyyy-MM-dd") + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/licenses" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} + diff --git a/SnipeitPS/Public/New-Location.ps1 b/SnipeitPS/Public/New-Location.ps1 index d6cce02..72e173d 100644 --- a/SnipeitPS/Public/New-Location.ps1 +++ b/SnipeitPS/Public/New-Location.ps1 @@ -47,6 +47,10 @@ function New-Location() { [string]$zip, + [int]$manager_id, + + [string]$ldap_ou, + [parameter(mandatory = $true)] [string]$url, @@ -54,14 +58,7 @@ function New-Location() { [string]$apiKey ) - $Values = @{ - name = $name - address = $address - address2 = $address2 - state = $state - country = $country - zip = $zip - } + $Values = . Get-ParameterValue $Body = $Values | ConvertTo-Json; diff --git a/SnipeitPS/Public/Set-Accessory.ps1 b/SnipeitPS/Public/Set-Accessory.ps1 new file mode 100644 index 0000000..276840a --- /dev/null +++ b/SnipeitPS/Public/Set-Accessory.ps1 @@ -0,0 +1,65 @@ + +function Set-Accessory() { + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [int]$id, + + [ValidateLength(3, 255)] + [string]$name, + + [int]$qty, + + [ValidateRange(1, [int]::MaxValue)] + [int]$category_id, + + [ValidateRange(1, [int]::MaxValue)] + [int]$company_id, + + [ValidateRange(1, [int]::MaxValue)] + [int]$manufacturer_id, + + [string]$order_number, + + [float]$purchase_cost, + + [datetime]$purchase_date, + + [bool]$requestable, + + [ValidateRange(1, [int]::MaxValue)] + [int]$supplier_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = . Get-ParameterValue + + if ($values['purchase_date']) { + $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/accessories/$id" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} + diff --git a/SnipeitPS/Public/Set-License.ps1 b/SnipeitPS/Public/Set-License.ps1 new file mode 100644 index 0000000..be2e760 --- /dev/null +++ b/SnipeitPS/Public/Set-License.ps1 @@ -0,0 +1,90 @@ + +function Set-License() { + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [int]$id, + + [ValidateLength(3, 255)] + [string]$name, + + [ValidateRange(1, [int]::MaxValue)] + [int]$seats, + + [ValidateRange(1, [int]::MaxValue)] + [int]$category_id, + + [ValidateRange(1, [int]::MaxValue)] + [int]$company_id, + + [datetime]$expiration_date, + + [ValidateLength(1, 120)] + [mailaddress]$license_email, + + [ValidateLength(1, 100)] + [string]$license_name, + + [bool]$maintained, + + [ValidateRange(1, [int]::MaxValue)] + [int]$manufacturer_id, + + [string]$notes, + + [string]$order_number, + + [float]$purchase_cost, + + [datetime]$purchase_date, + + [bool]$reassignable, + + [string]$serial, + + [ValidateRange(1, [int]::MaxValue)] + [int]$supplier_id, + + [datetime]$termination_date, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = . Get-ParameterValue + + if ($values['expiration_date']) { + $values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd") + } + + if ($values['purchase_date']) { + $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") + } + + if ($values['termination_date']) { + $values['termination_date'] = $values['termination_date'].ToString("yyyy-MM-dd") + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/licenses/$id" + Method = 'PUT' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} + diff --git a/SnipeitPS/Public/Set-Model.ps1 b/SnipeitPS/Public/Set-Model.ps1 index de372a5..62019f5 100644 --- a/SnipeitPS/Public/Set-Model.ps1 +++ b/SnipeitPS/Public/Set-Model.ps1 @@ -1,38 +1,3 @@ -<# - .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, @@ -41,20 +6,23 @@ function Set-Model() { Param( [parameter(mandatory = $true)] + [int]$id, + + [ValidateLength(1, 255)] [string]$name, + [ValidateLength(1, 255)] [string]$model_number, - [parameter(mandatory = $true)] [int]$category_id, - [parameter(mandatory = $true)] [int]$manufacturer_id, + [ValidateRange(1, 240)] [int]$eol, - [parameter(mandatory = $true)] - [int]$fieldset_id, + [Alias("fieldset_id")] + [int]$custom_fieldset_id, [parameter(mandatory = $true)] [string]$url, @@ -63,20 +31,12 @@ function Set-Model() { [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) } + $Values = Copy-Parameters -InputObject $PSBoundParameters $Body = $Values | ConvertTo-Json; $Parameters = @{ - Uri = "$url/api/v1/models" + Uri = "$url/api/v1/models/$id" Method = 'put' Body = $Body Token = $apiKey diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index fa60caeedbdfac1a65945525035def9aa4501a49..2d05b606d900e75a425bf9abdac880b483bdfee5 100644 GIT binary patch delta 129 zcmez5@y=^Qm>72^Lo!1uLmophL+WHh5$VYV;vBp_3`nAz4aIIVPL2?lkaT270YY5{ eN1zsvreYw>XDDK*glQDSCZmigx|vfVlLr7x^B%MS delta 17 ZcmaFo^~qyHnAqlRV%r!ub4aG~002x~2MYiI