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)
|
|
|
|
|
|
2021-07-08 23:59:31 +03:00
|
|
|
.PARAMETER image
|
2021-07-14 10:53:22 +03:00
|
|
|
Asset model Image filename and path
|
|
|
|
|
|
2017-11-20 09:07:58 +00:00
|
|
|
.PARAMETER url
|
2021-08-02 08:14:38 +03:00
|
|
|
Deprecated parameter, please use Connect-SnipeitPS instead. URL of Snipeit system.
|
2017-11-20 09:07:58 +00:00
|
|
|
|
|
|
|
|
.PARAMETER apiKey
|
2021-08-02 08:14:38 +03:00
|
|
|
Deprecated parameter, please use Connect-SnipeitPS instead. Users API Key for Snipeit.
|
2017-11-20 09:07:58 +00:00
|
|
|
|
|
|
|
|
.EXAMPLE
|
2021-06-08 20:23:32 +03:00
|
|
|
New-SnipeitModel -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1
|
2017-11-20 09:07:58 +00:00
|
|
|
#>
|
|
|
|
|
|
2021-08-02 08:14:38 +03:00
|
|
|
function New-SnipeitModel() {
|
2017-11-19 20:57:27 +00:00
|
|
|
[CmdletBinding(
|
|
|
|
|
SupportsShouldProcess = $true,
|
2018-01-22 08:32:04 +00:00
|
|
|
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,
|
|
|
|
|
|
2021-10-27 14:08:34 +03:00
|
|
|
[parameter(mandatory = $false)]
|
2017-11-19 20:57:27 +00:00
|
|
|
[int]$fieldset_id,
|
|
|
|
|
|
2021-07-08 23:59:31 +03:00
|
|
|
[ValidateScript({Test-Path $_})]
|
|
|
|
|
[string]$image,
|
|
|
|
|
|
2021-07-31 22:25:13 +03:00
|
|
|
[parameter(mandatory = $false)]
|
2017-11-19 20:57:27 +00:00
|
|
|
[string]$url,
|
|
|
|
|
|
2021-07-31 22:25:13 +03:00
|
|
|
[parameter(mandatory = $false)]
|
2017-11-19 20:57:27 +00:00
|
|
|
[string]$apiKey
|
|
|
|
|
)
|
|
|
|
|
|
2021-08-23 18:01:09 +03:00
|
|
|
begin {
|
|
|
|
|
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
|
|
|
|
|
|
|
|
|
$Values = @{
|
|
|
|
|
name = $name
|
|
|
|
|
category_id = $category_id
|
|
|
|
|
manufacturer_id = $manufacturer_id
|
|
|
|
|
fieldset_id = $fieldset_id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) }
|
|
|
|
|
if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$Parameters = @{
|
|
|
|
|
Api = "/api/v1/models"
|
|
|
|
|
Method = 'post'
|
|
|
|
|
Body = $Values
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 19:44:43 +03:00
|
|
|
if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
2021-08-23 18:01:09 +03:00
|
|
|
Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead."
|
|
|
|
|
Set-SnipeitPSLegacyApiKey -apiKey $apikey
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 19:44:43 +03:00
|
|
|
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) {
|
2021-08-23 18:01:09 +03:00
|
|
|
Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead."
|
|
|
|
|
Set-SnipeitPSLegacyUrl -url $url
|
|
|
|
|
}
|
2017-11-19 20:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-23 18:01:09 +03:00
|
|
|
process {
|
|
|
|
|
if ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
|
|
|
|
$result = Invoke-SnipeitMethod @Parameters
|
|
|
|
|
}
|
2017-11-19 20:57:27 +00:00
|
|
|
|
2021-08-23 18:01:09 +03:00
|
|
|
$result
|
2017-11-19 20:57:27 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-23 18:01:09 +03:00
|
|
|
end {
|
|
|
|
|
# reset legacy sessions
|
2021-09-03 19:44:43 +03:00
|
|
|
if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url -or $PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) {
|
2021-08-23 18:01:09 +03:00
|
|
|
Reset-SnipeitPSLegacyApi
|
|
|
|
|
}
|
2021-08-23 17:12:29 +03:00
|
|
|
}
|
2017-11-19 20:57:27 +00:00
|
|
|
}
|