Public/New-SnipeitComponent.ps1
<# .SYNOPSIS Create a new component .DESCRIPTION Createa new componen on Snipe-It system .PARAMETER name Component name .PARAMETER category_id ID number of category .PARAMETER qty Quantity of the components you have .PARAMETER location_id ID number of the location the accessory is assigned to .PARAMETER order_number Order number of the component .PARAMETER purchase_date Date accessory was purchased .PARAMETER purchase_cost Cost of item being purchased. .PARAMETER image Component 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 API Key for Snipeit. .EXAMPLE New-SnipeitComponent -name 'Display adapter' -catecory_id 3 -qty 10 #> function New-SnipeitComponent() { [CmdletBinding( SupportsShouldProcess = $true, ConfirmImpact = "Low" )] Param( [parameter(mandatory = $true)] [string]$name, [parameter(mandatory = $true)] [int]$category_id, [parameter(mandatory = $true)] [string]$qty, [int]$company_id, [int]$location_id, [string]$order_number, [datetime]$purchase_date, [float]$purchase_cost, [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 = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters if ($Values['purchase_date']) { $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd") } $Parameters = @{ Api = "/api/v1/components" 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 } } } |