55 . DESCRIPTION
66 Add a new Custom Field to Snipe-it asset system
77
8- . PARAMETER Name
9- Name of the Custom Field
8+ . PARAMETER name
9+ The field's name, which is also the form label
10+
11+ . PARAMETER element
12+ Form field type that should be displayed.
13+
14+ . PARAMETER field_values
15+ In the case of list boxes, etc, this should be a list of the options available
16+
17+ . PARAMETER show_in_email
18+ Whether or not to show the custom field in email notifications
19+
20+ . PARAMETER format
21+ How the field should be validated
22+
23+ . PARAMETER custom_format
24+ In the case of format 'CUSTOM REGEX', this should be validation regex this field
25+
26+ . PARAMETER field_encrypted
27+ Whether the field should be encrypted. (This can cause issues if you change it after the field was created.)
28+
29+ . PARAMETER help_text
30+ Any additional text you wish to display under the new form field to make it clearer what the gauges should be.
1031
1132 . PARAMETER url
1233 URL of Snipeit system, can be set using Set-SnipeitInfo command
@@ -27,17 +48,25 @@ function New-SnipeitCustomField()
2748
2849 Param (
2950 [parameter (mandatory = $true )]
30- [string ]$Name ,
51+ [string ]$name ,
3152
32- [string ]$HelpText ,
53+ [string ]$help_text ,
3354
34- [string ]$Element = " text" ,
55+ [parameter (mandatory = $true )]
56+ [ValidateSet (' text' , ' textarea' , ' listbox' , ' checkbox' , ' radio' )]
57+ [string ]$element ,
58+
59+ [parameter (mandatory = $true )]
60+ [ValidateSet (' ANY' , ' CUSTOM REGEX' , ' ALPHA' , ' ALPHA-DASH' , ' NUMERIC' , ' ALPHA-NUMERIC' , ' EMAIL' , ' DATE' , ' URL' , ' IP' , ' IPV4' , ' IPV6' , ' MAC' , ' BOOLEAN' )]
61+ [string ]$format ,
62+
63+ [string ]$field_values ,
3564
36- [string ] $Format = " ANY " ,
65+ [bool ] $field_encrypted = $false ,
3766
38- [bool ]$field_encrypted ,
67+ [bool ]$show_in_email = $false ,
3968
40- [string ]$CustomFormat ,
69+ [string ]$custom_format ,
4170
4271 [parameter (mandatory = $true )]
4372 [string ]$url ,
@@ -46,24 +75,31 @@ function New-SnipeitCustomField()
4675 [string ]$apiKey
4776 )
4877
49- Test-SnipeitAlias - invocationName $MyInvocation.InvocationName - commandName $MyInvocation.MyCommand.Name
78+ begin {
79+ Test-SnipeitAlias - invocationName $MyInvocation.InvocationName - commandName $MyInvocation.MyCommand.Name
80+ if ($format -eq ' CUSTOM REGEX' -and (-not $custom_format )) {
81+ throw " Please specify regex validation with -custom_format when using -format 'CUSTOM REGEX'"
82+ }
5083
51- $Values = . Get-ParameterValue - Parameters $MyInvocation.MyCommand.Parameters - BoundParameters $PSBoundParameters
84+ $Values = . Get-ParameterValue - Parameters $MyInvocation.MyCommand.Parameters - BoundParameters $PSBoundParameters
5285
53- # Convert Values to JSON format
54- $Body = $Values | ConvertTo-Json ;
86+ $Body = $Values | ConvertTo-Json ;
5587
56- $Parameters = @ {
57- Uri = " $url /api/v1/fields"
58- Method = ' post'
59- Body = $Body
60- Token = $apiKey
88+ $Parameters = @ {
89+ Uri = " $url /api/v1/fields"
90+ Method = ' post'
91+ Body = $Body
92+ Token = $apiKey
93+ }
6194 }
6295
63- If ($PSCmdlet.ShouldProcess (" ShouldProcess?" ))
64- {
65- $result = Invoke-SnipeitMethod @Parameters
66- }
96+ process {
97+ If ($PSCmdlet.ShouldProcess (" ShouldProcess?" ))
98+ {
99+ $result = Invoke-SnipeitMethod @Parameters
100+ }
67101
68- $result
102+ $result
103+ }
69104}
105+
0 commit comments