Public/New-SnipeitModel.ps1
<# .SYNOPSIS Add a new Model to Snipe-it asset system .DESCRIPTION Long description .PARAMETER name Name of the Asset Model .PARAMETER model_number Model number of the Asset Model .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 image Asset model Image filename and path .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-SnipeitModel -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1 #> function New-SnipeitModel() { [CmdletBinding( SupportsShouldProcess = $true, ConfirmImpact = "Low" )] Param( [parameter(mandatory = $true)] [string]$name, [string]$model_number, [parameter(mandatory = $true)] [int]$category_id, [parameter(mandatory = $true)] [int]$manufacturer_id, [int]$eol, [parameter(mandatory = $false)] [int]$fieldset_id, [ValidateScript({Test-Path $_})] [string]$image, [parameter(mandatory = $false)] [string]$url, [parameter(mandatory = $false)] [string]$apiKey ) 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 } if ($PSBoundParameters.ContainsKey('apiKey') -and '' -ne [string]$apiKey) { Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." Set-SnipeitPSLegacyApiKey -apiKey $apikey } if ($PSBoundParameters.ContainsKey('url') -and '' -ne [string]$url) { Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." 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 } } } |