Added Cmdlet New-SnipeItCustomFieldset

This commit is contained in:
Frank Geisler 2023-08-18 08:19:20 +02:00
parent a016c4eb54
commit 865a07d4ad
2 changed files with 74 additions and 0 deletions

View file

@ -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
}
}
}

View file

@ -100,6 +100,7 @@ FunctionsToExport = @(
'New-SnipeitComponent',
'New-SnipeitConsumable',
'New-SnipeitCustomField',
'New-SnipeitCustomFieldSet',
'New-SnipeitDepartment',
'New-SnipeitLicense',
'New-SnipeitLocation',