diff --git a/SnipeitPS/Public/New-SnipeitCustomFieldset.ps1 b/SnipeitPS/Public/New-SnipeitCustomFieldset.ps1 new file mode 100644 index 0000000..625da07 --- /dev/null +++ b/SnipeitPS/Public/New-SnipeitCustomFieldset.ps1 @@ -0,0 +1,73 @@ +<# + .SYNOPSIS + Add a new Custom Fieldset to Snipe-it asset system + + .DESCRIPTION + Add a new Custom Field Set to Snipe-it asset system + + .PARAMETER name + The fieldsets's name + + .PARAMETER url + Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system. + + .PARAMETER apiKey + Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit. + + .EXAMPLE + New-SnipeitCustomFieldSet -Name "Notebook Fields" +#> + +function New-SnipeitCustomFieldSet() { + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [string]$name, + + [parameter(mandatory = $false)] + [string]$url, + + [parameter(mandatory = $false)] + [string]$apiKey + ) + + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + + $Parameters = @{ + Api = "/api/v1/fieldsets" + Method = 'post' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) { + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) { + Set-SnipeitPSLegacyUrl -url $url + } + } + + process{ + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) { + Reset-SnipeitPSLegacyApi + } + } +} + diff --git a/SnipeitPS/Public/New-SnipeitLicense.ps1 b/SnipeitPS/Public/New-SnipeitLicense.ps1 index 74ea39a..f777df3 100644 --- a/SnipeitPS/Public/New-SnipeitLicense.ps1 +++ b/SnipeitPS/Public/New-SnipeitLicense.ps1 @@ -47,6 +47,9 @@ .PARAMETER purchase_date Date of license purchase + .PARAMETER purchase_order + Purchase order number of license purchase + .PARAMETER reassignable Is license reassignable? @@ -89,7 +92,6 @@ function New-SnipeitLicense() { [datetime]$expiration_date, - [ValidateLength(1, 120)] [mailaddress]$license_email, [ValidateLength(1, 100)] @@ -108,6 +110,8 @@ function New-SnipeitLicense() { [datetime]$purchase_date, + [string]$purchase_order, + [bool]$reassignable, [string]$serial, @@ -140,6 +144,10 @@ function New-SnipeitLicense() { $Values['termination_date'] = $Values['termination_date'].ToString("yyyy-MM-dd") } + if ($Values['license_email']) { + $Values['license_email'] = $Values['license_email'].address + } + $Parameters = @{ Api = "/api/v1/licenses" Method = 'POST' diff --git a/SnipeitPS/Public/New-SnipeitSupplier.ps1 b/SnipeitPS/Public/New-SnipeitSupplier.ps1 index 599dbe0..3038381 100644 --- a/SnipeitPS/Public/New-SnipeitSupplier.ps1 +++ b/SnipeitPS/Public/New-SnipeitSupplier.ps1 @@ -102,7 +102,7 @@ function New-SnipeitSupplier() { $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters $Parameters = @{ - Api = "/api/v1/suppilers" + Api = "/api/v1/suppliers" Method = 'POST' Body = $Values } diff --git a/SnipeitPS/Public/New-SnipeitUser.ps1 b/SnipeitPS/Public/New-SnipeitUser.ps1 index 30f42dd..1a7776a 100644 --- a/SnipeitPS/Public/New-SnipeitUser.ps1 +++ b/SnipeitPS/Public/New-SnipeitUser.ps1 @@ -14,11 +14,11 @@ .PARAMETER username Username for user - .PARAMETER active + .PARAMETER activated Can user log in to snipe-it? .PARAMETER password - Password for user + Password for user. The password should at least be 8 characters long. .PARAMETER notes User Notes @@ -63,7 +63,7 @@ Deprecated parameter, please use Connect-SnipeitPS instead. User's API Key for Snipeit. .EXAMPLE - New-Snipeituser -fist_name It -lastname Snipe -username snipeit -activated $false -company_id 1 -location_id 1 -department_id 1 + New-Snipeituser -first_name It -last_name Snipe -username snipeit -activated $false -company_id 1 -location_id 1 -department_id 1 Creates new a new user who can't login to system .NOTES @@ -86,6 +86,8 @@ function New-SnipeitUser() { [parameter(mandatory = $true)] [string]$username, + [ValidateScript({$_.Length -ge 8}, ErrorMessage = "Password should be at least 8 characters.")] + [parameter(mandatory = $true)] [string]$password, [bool]$activated = $false, @@ -122,6 +124,7 @@ function New-SnipeitUser() { [string]$apiKey ) begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters diff --git a/SnipeitPS/Public/Set-SnipeitLicense.ps1 b/SnipeitPS/Public/Set-SnipeitLicense.ps1 index 21bfa9f..9d9e322 100644 --- a/SnipeitPS/Public/Set-SnipeitLicense.ps1 +++ b/SnipeitPS/Public/Set-SnipeitLicense.ps1 @@ -50,6 +50,9 @@ .PARAMETER purchase_date Date of license purchase + .PARAMETER purchase_order + Purchase order number of license purchase + .PARAMETER reassignable Is license reassignable? @@ -116,6 +119,8 @@ function Set-SnipeitLicense() { [datetime]$purchase_date, + [string]$purchase_order, + [bool]$reassignable, [string]$serial, @@ -151,6 +156,9 @@ function Set-SnipeitLicense() { $Values['termination_date'] = $Values['termination_date'].ToString("yyyy-MM-dd") } + if ($Values['license_email']) { + $Values['license_email'] = $Values['license_email'].address + } } process { diff --git a/SnipeitPS/SnipeitPS.psd1 b/SnipeitPS/SnipeitPS.psd1 index c742924..fb78e75 100644 --- a/SnipeitPS/SnipeitPS.psd1 +++ b/SnipeitPS/SnipeitPS.psd1 @@ -100,6 +100,7 @@ FunctionsToExport = @( 'New-SnipeitComponent', 'New-SnipeitConsumable', 'New-SnipeitCustomField', + 'New-SnipeitCustomFieldSet', 'New-SnipeitDepartment', 'New-SnipeitLicense', 'New-SnipeitLocation', diff --git a/docs/New-SnipeitAsset.md b/docs/New-SnipeitAsset.md index 02d563d..9b2d05d 100644 --- a/docs/New-SnipeitAsset.md +++ b/docs/New-SnipeitAsset.md @@ -49,7 +49,7 @@ Specifying asset tag when creating asset ### EXAMPLE 3 ``` -New-SnipeitAsset -status_id 1 -model_id 1 -name "Machine1" -customfields = @{ "_snipeit_os_5" = "Windows 10 Pro" } +New-SnipeitAsset -status_id 1 -model_id 1 -name "Machine1" -customfields @{ "_snipeit_os_5" = "Windows 10 Pro" } Using customfields when creating asset. ``` diff --git a/docs/Set-SnipeitAsset.md b/docs/Set-SnipeitAsset.md index 7952df5..0770fc0 100644 --- a/docs/Set-SnipeitAsset.md +++ b/docs/Set-SnipeitAsset.md @@ -33,7 +33,7 @@ Set-SnipeitAsset -id 1 -status_id 1 -model_id 1 -name "Machine1" ### EXAMPLE 2 ``` -Set-SnipeitAsset -id 1 -name "Machine1" -customfields = @{ "_snipeit_os_5" = "Windows 10 Pro" ; "_snipeit_os_version" = "1909" } +Set-SnipeitAsset -id 1 -name "Machine1" -customfields @{ "_snipeit_os_5" = "Windows 10 Pro" ; "_snipeit_os_version" = "1909" } ``` ### EXAMPLE 3