From d3fb9762abc52e50e33af1f43f32e277dc75b52b Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Thu, 11 Feb 2021 15:23:34 +0200 Subject: [PATCH 1/3] Fix for #77 and add activated as parameter --- SnipeitPS/Public/New-User.ps1 | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/SnipeitPS/Public/New-User.ps1 b/SnipeitPS/Public/New-User.ps1 index d18e21c..23eb3b0 100644 --- a/SnipeitPS/Public/New-User.ps1 +++ b/SnipeitPS/Public/New-User.ps1 @@ -68,11 +68,11 @@ function New-User() { [string]$lastName, [parameter(mandatory = $true)] - [string]$userName, + [string]$username, [string]$password, - [string]$jobTitle, + [string]$jobtitle, [string]$email, @@ -90,33 +90,27 @@ function New-User() { [bool]$ldap_user = $false, + [bool]$activated = $false, + [parameter(mandatory = $true)] [string]$url, [parameter(mandatory = $true)] [string]$apiKey ) - - $Values = @{ - first_name = $firstName - last_name = $lastName - username = $userName - - email = $email - phone = $phone - company_id = $company_id - location_id = $location_id - department_id = $department_id - manager_id = $manager_id - jobtitle = $jobTitle - employee_num = $employee_num - notes = "Imported using SnipeitPS Script" - activated = 1 + $Values= @{} + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters + if($Values.ContainsKey('firstname')) { + $Values['first_name']=$Values['firstname'] + $Values.Remove('firstname') } - + if($Values.ContainsKey('lastname')) { + $Values['last_name']=$Values['lastname'] + $Values.Remove('lastname') + } + if ($ldap_user -eq $false) { $ldap = @{ - password = $password password_confirmation = $password ldap_import = 0 } From ddb0036156d15e874f089dd212865607f635f019 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Thu, 11 Feb 2021 21:05:06 +0200 Subject: [PATCH 2/3] same parameter names as api and removed ldap logic --- SnipeitPS/Public/New-User.ps1 | 57 +++++++++++++++-------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/SnipeitPS/Public/New-User.ps1 b/SnipeitPS/Public/New-User.ps1 index 23eb3b0..ec77a10 100644 --- a/SnipeitPS/Public/New-User.ps1 +++ b/SnipeitPS/Public/New-User.ps1 @@ -5,16 +5,22 @@ .DESCRIPTION Long description - .PARAMETER firstName + .PARAMETER first_name Parameter description - .PARAMETER lastName + .PARAMETER last_name Parameter description - .PARAMETER userName + .PARAMETER username Parameter description - .PARAMETER jobTitle + .PARAMETER active + Parameter description + + .PARAMETER notes + Parameter description + + .PARAMETER jobtitle Parameter description .PARAMETER email @@ -38,8 +44,8 @@ .PARAMETER employee_num Parameter description - .PARAMETER ldap_user - Parameter description + .PARAMETER ldap_import + Mark user as import from ldap .PARAMETER url Parameter description @@ -62,16 +68,20 @@ function New-User() { Param( [parameter(mandatory = $true)] - [string]$firstName, + [string]$first_name, [parameter(mandatory = $true)] - [string]$lastName, + [string]$last_name, [parameter(mandatory = $true)] [string]$username, [string]$password, + [bool]$activated = $false, + + [string]$notes, + [string]$jobtitle, [string]$email, @@ -88,41 +98,22 @@ function New-User() { [string]$employee_num, - [bool]$ldap_user = $false, - - [bool]$activated = $false, + [bool]$ldap_import = $false, + [parameter(mandatory = $true)] [string]$url, [parameter(mandatory = $true)] [string]$apiKey ) - $Values= @{} + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters - if($Values.ContainsKey('firstname')) { - $Values['first_name']=$Values['firstname'] - $Values.Remove('firstname') - } - if($Values.ContainsKey('lastname')) { - $Values['last_name']=$Values['lastname'] - $Values.Remove('lastname') + + if ($password ) { + $Values['password_confirmation'] = $password } - if ($ldap_user -eq $false) { - $ldap = @{ - password_confirmation = $password - ldap_import = 0 - } - $Values += $ldap - } - else { - $ldap = @{ - ldap_import = 1 - } - $Values += $ldap - } - $Body = $Values | ConvertTo-Json; $Parameters = @{ From a4bc6bb3f0865e72a54300108d688191698ad108 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Thu, 18 Feb 2021 19:43:26 +0200 Subject: [PATCH 3/3] Keep asset tag optional as in api+ more parameters --- SnipeitPS/Public/New-Asset.ps1 | 94 +++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 24 deletions(-) diff --git a/SnipeitPS/Public/New-Asset.ps1 b/SnipeitPS/Public/New-Asset.ps1 index 1362770..3513937 100644 --- a/SnipeitPS/Public/New-Asset.ps1 +++ b/SnipeitPS/Public/New-Asset.ps1 @@ -5,17 +5,42 @@ .DESCRIPTION Long description - .PARAMETER Tag - Asset Tag for the Asset - .PARAMETER Name - Name of the Asset + .PARAMETER status_id + Required Status ID of the asset, this can be got using Get-Status - .PARAMETER Status_id - Status ID of the asset, this can be got using Get-Status + .PARAMETER model_id + Required Model ID of the asset, this can be got using Get-Model - .PARAMETER Model_id - Model ID of the asset, this can be got using Get-Model + .PARAMETER name + Optional Name of the Asset + + .PARAMETER asset_tag + Asset Tag for the Asset, not required when snipe asset_tag autogeneration is on. + + .PARAMETER serial + Optional Serial number of the Asset + + .PARAMETER company_id + Optional Company id + + .PARAMETER order_number + Optional Order number + + .PARAMETER notes + Optional Notes + + .PARAMETER warranty_monhts + Optional Warranty lenght of the Asset in months + + .PARAMETER purchase_cost + Optional Purchase cost of the Asset + + .PARAMETER purchase_date + Optional Purchase cost of the Asset + + .PARAMETER rtd_location_id + Optional Default location id for the asset .PARAMETER url URL of Snipeit system, can be set using Set-Info command @@ -41,16 +66,45 @@ function New-Asset() )] Param( - [string]$tag, + + [parameter(mandatory = $true)] + [int]$status_id, [parameter(mandatory = $true)] - [string]$Name, + [int]$model_id, - [parameter(mandatory = $true)] - [int]$Status_id, + [parameter(mandatory = $false)] + [string]$name, - [parameter(mandatory = $true)] - [int]$Model_id, + [parameter(mandatory = $false)] + [string]$asset_tag, + + [parameter(mandatory = $false)] + [string]$serial, + + [parameter(mandatory = $false)] + [int]$company_id, + + [parameter(mandatory = $false)] + [string]$order_number, + + [parameter(mandatory = $false)] + [string]$notes, + + [parameter(mandatory = $false)] + [int]$warranty_months, + + [parameter(mandatory = $false)] + [string]$purchase_cost, + + [parameter(mandatory = $false)] + [string]$purchase_date, + + [parameter(mandatory = $false)] + [int]$supplier_id, + + [parameter(mandatory = $false)] + [int]$rtd_location_id, [parameter(mandatory = $true)] [string]$url, @@ -61,16 +115,8 @@ function New-Asset() [hashtable] $customfields ) - $Values = @{ - "name" = $Name - "status_id" = $status_id - "model_id" = $model_id - } - - if ($PSBoundParameters.ContainsKey('tag')) - { - $Values += @{"asset_tag" = $tag} - } + $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters + if ($customfields) {