SnipeitPS/SnipeitPS/Public/Set-Components.ps1

94 lines
1.6 KiB
PowerShell
Raw Normal View History

2021-05-19 15:51:49 +03:00
<#
.SYNOPSIS
Updates component
.DESCRIPTION
Updates component on Snipe-It system
.PARAMETER id
ID number of name
.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 purchase_date
Date accessory was purchased
.PARAMETER purchase_cost
Cost of item being purchased.
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
.PARAMETER apiKey
User's API Key for Snipeit, can be set using Set-Info command
.EXAMPLE
An example
.NOTES
General notes
#>
2017-11-19 20:57:27 +00:00
function Set-Component()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Medium"
2017-11-19 20:57:27 +00:00
)]
Param(
[parameter(mandatory = $true)]
[string]$id,
[parameter(mandatory = $true)]
[string]$qty,
2021-05-19 15:51:49 +03:00
[string]$name,
[int]$company_id,
[int]$location_id,
[datetime]$purchase_date,
[float]$purchase_cost,
2017-11-19 20:57:27 +00:00
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
2021-05-19 15:51:49 +03:00
$values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
2017-11-19 20:57:27 +00:00
}
2021-05-19 15:51:49 +03:00
$Body = $values | ConvertTo-Json;
2017-11-19 20:57:27 +00:00
$Parameters = @{
2021-05-17 10:07:17 +03:00
Uri = "$url/api/v1/components/$id"
2017-11-19 20:57:27 +00:00
Method = 'Patch'
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
}