SnipeitPS/SnipeitPS/Public/New-Accessory.ps1
Petri Asikainen 6828244dfa #67
2021-01-29 18:08:19 +02:00

65 lines
1.4 KiB
PowerShell

function New-Accessory() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[ValidateLength(3, 255)]
[string]$name,
[parameter(mandatory = $true)]
[int]$qty,
[parameter(mandatory = $true)]
[ValidateRange(1, [int]::MaxValue)]
[int]$category_id,
[ValidateRange(1, [int]::MaxValue)]
[int]$company_id,
[ValidateRange(1, [int]::MaxValue)]
[int]$manufacturer_id,
[string]$order_number,
[float]$purchase_cost,
[datetime]$purchase_date,
[bool]$requestable,
[ValidateRange(1, [int]::MaxValue)]
[int]$supplier_id,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/accessories"
Method = 'POST'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}