set-snipeitcomponent

This commit is contained in:
Petri Asikainen 2021-06-13 18:35:43 +03:00
parent dfb271dbec
commit 83eb363889

View file

@ -49,8 +49,8 @@ function Set-SnipeitComponent()
)] )]
Param( Param(
[parameter(mandatory = $true)] [parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int]$id, [int[]]$id,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[int]$qty, [int]$qty,
@ -74,28 +74,33 @@ function Set-SnipeitComponent()
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$apiKey [string]$apiKey
) )
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name $values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
if ($values['purchase_date']) { $Body = $values | ConvertTo-Json;
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
} }
$Body = $values | ConvertTo-Json; process {
foreach($component_id in $id){
$Parameters = @{
Uri = "$url/api/v1/components/$component_id"
Method = 'Patch'
Body = $Body
Token = $apiKey
}
$Parameters = @{ If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
Uri = "$url/api/v1/components/$id" {
Method = 'Patch' $result = Invoke-SnipeitMethod @Parameters
Body = $Body }
Token = $apiKey
$result
}
} }
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
} }