mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-13 18:02:30 +00:00
get-set snipeitcustomfield
This commit is contained in:
parent
621ee76709
commit
b35230e3b8
2 changed files with 166 additions and 22 deletions
|
|
@ -5,8 +5,29 @@
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Add a new Custom Field to Snipe-it asset system
|
Add a new Custom Field to Snipe-it asset system
|
||||||
|
|
||||||
.PARAMETER Name
|
.PARAMETER name
|
||||||
Name of the Custom Field
|
The field's name, which is also the form label
|
||||||
|
|
||||||
|
.PARAMETER element
|
||||||
|
Form field type that should be displayed.
|
||||||
|
|
||||||
|
.PARAMETER field_values
|
||||||
|
In the case of list boxes, etc, this should be a list of the options available
|
||||||
|
|
||||||
|
.PARAMETER show_in_email
|
||||||
|
Whether or not to show the custom field in email notifications
|
||||||
|
|
||||||
|
.PARAMETER format
|
||||||
|
How the field should be validated
|
||||||
|
|
||||||
|
.PARAMETER custom_format
|
||||||
|
In the case of format 'CUSTOM REGEX', this should be validation regex this field
|
||||||
|
|
||||||
|
.PARAMETER field_encrypted
|
||||||
|
Whether the field should be encrypted. (This can cause issues if you change it after the field was created.)
|
||||||
|
|
||||||
|
.PARAMETER help_text
|
||||||
|
Any additional text you wish to display under the new form field to make it clearer what the gauges should be.
|
||||||
|
|
||||||
.PARAMETER url
|
.PARAMETER url
|
||||||
URL of Snipeit system, can be set using Set-SnipeitInfo command
|
URL of Snipeit system, can be set using Set-SnipeitInfo command
|
||||||
|
|
@ -27,17 +48,25 @@ function New-SnipeitCustomField()
|
||||||
|
|
||||||
Param(
|
Param(
|
||||||
[parameter(mandatory = $true)]
|
[parameter(mandatory = $true)]
|
||||||
[string]$Name,
|
[string]$name,
|
||||||
|
|
||||||
[string]$HelpText,
|
[string]$help_text,
|
||||||
|
|
||||||
[string]$Element = "text",
|
[parameter(mandatory = $true)]
|
||||||
|
[ValidateSet('text','textarea','listbox','checkbox','radio')]
|
||||||
|
[string]$element ,
|
||||||
|
|
||||||
[string]$Format = "ANY",
|
[parameter(mandatory = $true)]
|
||||||
|
[ValidateSet('ANY','CUSTOM REGEX','ALPHA','ALPHA-DASH','NUMERIC','ALPHA-NUMERIC','EMAIL','DATE','URL','IP','IPV4','IPV6','MAC','BOOLEAN')]
|
||||||
|
[string]$format,
|
||||||
|
|
||||||
[bool]$field_encrypted,
|
[string]$field_values,
|
||||||
|
|
||||||
[string]$CustomFormat,
|
[bool]$field_encrypted=$false,
|
||||||
|
|
||||||
|
[bool]$show_in_email=$false,
|
||||||
|
|
||||||
|
[string]$custom_format,
|
||||||
|
|
||||||
[parameter(mandatory = $true)]
|
[parameter(mandatory = $true)]
|
||||||
[string]$url,
|
[string]$url,
|
||||||
|
|
@ -46,24 +75,31 @@ function New-SnipeitCustomField()
|
||||||
[string]$apiKey
|
[string]$apiKey
|
||||||
)
|
)
|
||||||
|
|
||||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
begin {
|
||||||
|
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||||
|
if ($format -eq 'CUSTOM REGEX' -and (-not $custom_format)) {
|
||||||
|
throw "Please specify regex validation with -custom_format when using -format 'CUSTOM REGEX'"
|
||||||
|
}
|
||||||
|
|
||||||
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||||
|
|
||||||
#Convert Values to JSON format
|
$Body = $Values | ConvertTo-Json;
|
||||||
$Body = $Values | ConvertTo-Json;
|
|
||||||
|
|
||||||
$Parameters = @{
|
$Parameters = @{
|
||||||
Uri = "$url/api/v1/fields"
|
Uri = "$url/api/v1/fields"
|
||||||
Method = 'post'
|
Method = 'post'
|
||||||
Body = $Body
|
Body = $Body
|
||||||
Token = $apiKey
|
Token = $apiKey
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
process{
|
||||||
{
|
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
||||||
$result = Invoke-SnipeitMethod @Parameters
|
{
|
||||||
}
|
$result = Invoke-SnipeitMethod @Parameters
|
||||||
|
}
|
||||||
|
|
||||||
$result
|
$result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
108
SnipeitPS/Public/Set-SnipeitCustomField.ps1
Normal file
108
SnipeitPS/Public/Set-SnipeitCustomField.ps1
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Add a new Custom Field to Snipe-it asset system
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
Add a new Custom Field to Snipe-it asset system
|
||||||
|
|
||||||
|
.PARAMETER name
|
||||||
|
The field's name, which is also the form label
|
||||||
|
|
||||||
|
.PARAMETER element
|
||||||
|
Form field type that should be displayed.
|
||||||
|
|
||||||
|
.PARAMETER field_values
|
||||||
|
In the case of list boxes, etc, this should be a list of the options available
|
||||||
|
|
||||||
|
.PARAMETER show_in_email
|
||||||
|
Whether or not to show the custom field in email notifications
|
||||||
|
|
||||||
|
.PARAMETER format
|
||||||
|
How the field should be validated
|
||||||
|
|
||||||
|
.PARAMETER custom_format
|
||||||
|
In the case of format 'CUSTOM REGEX', this should be validation regex this field
|
||||||
|
|
||||||
|
.PARAMETER field_encrypted
|
||||||
|
Whether the field should be encrypted. (This can cause issues if you change it after the field was created.)
|
||||||
|
|
||||||
|
.PARAMETER help_text
|
||||||
|
Any additional text you wish to display under the new form field to make it clearer what the gauges should be.
|
||||||
|
|
||||||
|
.PARAMETER url
|
||||||
|
URL of Snipeit system, can be set using Set-SnipeitInfo command
|
||||||
|
|
||||||
|
.PARAMETER apiKey
|
||||||
|
Users API Key for Snipeit, can be set using Set-SnipeitInfo command
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
New-SnipeitCustomField -Name "AntivirusInstalled" -Format "BOOLEAN" -HelpText "Is AntiVirus installed on Asset"
|
||||||
|
#>
|
||||||
|
|
||||||
|
function Set-SnipeitCustomField()
|
||||||
|
{
|
||||||
|
[CmdletBinding(
|
||||||
|
SupportsShouldProcess = $true,
|
||||||
|
ConfirmImpact = "Low"
|
||||||
|
)]
|
||||||
|
|
||||||
|
Param(
|
||||||
|
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
|
||||||
|
[int[]]$id,
|
||||||
|
|
||||||
|
[string]$name,
|
||||||
|
|
||||||
|
[string]$help_text,
|
||||||
|
|
||||||
|
[parameter(Mandatory=$true)]
|
||||||
|
[ValidateSet('text','textarea','listbox','checkbox','radio')]
|
||||||
|
[string]$element ,
|
||||||
|
|
||||||
|
[ValidateSet('ANY','CUSTOM REGEX','ALPHA','ALPHA-DASH','NUMERIC','ALPHA-NUMERIC','EMAIL','DATE','URL','IP','IPV4','IPV6','MAC','BOOLEAN')]
|
||||||
|
[string]$format,
|
||||||
|
|
||||||
|
[string]$field_values,
|
||||||
|
|
||||||
|
[bool]$field_encrypted,
|
||||||
|
|
||||||
|
[bool]$show_in_email,
|
||||||
|
|
||||||
|
[string]$custom_format,
|
||||||
|
|
||||||
|
[parameter(mandatory = $true)]
|
||||||
|
[string]$url,
|
||||||
|
|
||||||
|
[parameter(mandatory = $true)]
|
||||||
|
[string]$apiKey
|
||||||
|
)
|
||||||
|
begin {
|
||||||
|
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
||||||
|
if ($format -eq 'CUSTOM REGEX' -and (-not $custom_format)) {
|
||||||
|
throw "Please specify regex validation with -custom_format when using -format 'CUSTOM REGEX'"
|
||||||
|
}
|
||||||
|
|
||||||
|
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||||
|
|
||||||
|
$Body = $Values | ConvertTo-Json;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
process{
|
||||||
|
foreach($field_id in $id) {
|
||||||
|
$Parameters = @{
|
||||||
|
Uri = "$url/api/v1/fields/$field_id"
|
||||||
|
Method = 'Put'
|
||||||
|
Body = $Body
|
||||||
|
Token = $apiKey
|
||||||
|
}
|
||||||
|
|
||||||
|
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
||||||
|
{
|
||||||
|
$result = Invoke-SnipeitMethod @Parameters
|
||||||
|
}
|
||||||
|
|
||||||
|
$result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Add table
Reference in a new issue