SnipeitPS/SnipeitPS/Public/Set-SnipeitModel.ps1
2021-09-03 19:44:43 +03:00

122 lines
3.3 KiB
PowerShell

<#
.SYNOPSIS
Updates Model on Snipe-it asset system
.DESCRIPTION
Updates Model on Snipe-it asset system
.PARAMETER id
ID number of the Asset Model or array of IDs
.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
Image file name and path for item
.PARAMETER image_delete
Remove current image
.PARAMETER RequestType
Http request type to send Snipe IT system. Defaults to Patch you could use Put if needed.
.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 Set-SnipeitModel() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Medium"
)]
Param(
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[ValidateLength(1, 255)]
[string]$name,
[string]$model_number,
[int]$category_id,
[int]$manufacturer_id,
[Nullable[System.Int32]]$eol,
[Alias("fieldset_id")]
[Nullable[System.Int32]]$custom_fieldset_id,
[ValidateScript({Test-Path $_})]
[string]$image,
[switch]$image_delete=$false,
[ValidateSet("Put","Patch")]
[string]$RequestType = "Patch",
[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
}
process {
foreach ($model_id in $id) {
$Parameters = @{
Api = "/api/v1/models/$model_id"
Method = $RequestType
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
}
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
}
}
}