SnipeitPS/SnipeitPS/Public/New-SnipeitModel.ps1

92 lines
2.1 KiB
PowerShell
Raw Normal View History

2017-11-20 09:07:58 +00:00
<#
.SYNOPSIS
Add a new Model to Snipe-it asset system
.DESCRIPTION
Long description
.PARAMETER name
Name of the Asset Model
2021-05-19 15:51:49 +03:00
.PARAMETER model_number
Model number of the Asset Model
2017-11-20 09:07:58 +00:00
.PARAMETER category_id
Category ID that the asset belongs to this can be got using Get-Category
.PARAMETER manufacturer_id
Manufacturer ID that the asset belongs to this can be got using Get-Manufacturer
.PARAMETER fieldset_id
Fieldset ID that the asset uses (Custom fields)
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeItInfo command
2017-11-20 09:07:58 +00:00
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-SnipeItInfo command
2017-11-20 09:07:58 +00:00
.EXAMPLE
2021-05-23 23:22:23 +03:00
New-SnipeItModel -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1
2017-11-20 09:07:58 +00:00
#>
function New-SnipeItModel()
2017-11-19 20:57:27 +00:00
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
2017-11-19 20:57:27 +00:00
)]
Param(
[parameter(mandatory = $true)]
[string]$name,
2019-04-26 16:30:00 +01:00
[string]$model_number,
2017-11-19 20:57:27 +00:00
[parameter(mandatory = $true)]
[int]$category_id,
[parameter(mandatory = $true)]
[int]$manufacturer_id,
2019-04-26 16:30:00 +01:00
[int]$eol,
2017-11-19 20:57:27 +00:00
[parameter(mandatory = $true)]
[int]$fieldset_id,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
2021-05-23 19:23:24 +03:00
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
2017-11-19 20:57:27 +00:00
$Values = @{
name = $name
category_id = $category_id
manufacturer_id = $manufacturer_id
fieldset_id = $fieldset_id
}
2019-04-26 16:30:00 +01:00
if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) }
if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) }
2017-11-19 20:57:27 +00:00
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/models"
Method = 'post'
Body = $Body
Token = $apiKey
}
2017-11-20 09:12:54 +00:00
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
2017-11-19 20:57:27 +00:00
{
$result = Invoke-SnipeitMethod @Parameters
2017-11-19 20:57:27 +00:00
}
$result
}