2021-05-19 15:51:49 +03:00
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Add a new Asset maintenence to Snipe-it asset system
|
|
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
Long description
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.PARAMETER title
|
|
|
|
|
Required Title of maintenance
|
|
|
|
|
|
|
|
|
|
.PARAMETER asset_id
|
|
|
|
|
Required ID of the asset, this can be got using Get-Asset
|
|
|
|
|
|
|
|
|
|
.PARAMETER supplier_id
|
|
|
|
|
Required maintenance supplier
|
|
|
|
|
|
|
|
|
|
.PARAMETER start_date
|
|
|
|
|
Required start date
|
|
|
|
|
|
|
|
|
|
.PARAMETER is_warranty
|
|
|
|
|
Optional Maintenance done under warranty
|
|
|
|
|
|
|
|
|
|
.PARAMETER cost
|
|
|
|
|
Optional cost
|
|
|
|
|
|
|
|
|
|
.PARAMETER comletion_date
|
|
|
|
|
Optional completion date
|
|
|
|
|
|
|
|
|
|
.PARAMETER notes
|
|
|
|
|
Optional cost
|
|
|
|
|
|
|
|
|
|
.PARAMETER url
|
2021-05-22 18:44:36 +03:00
|
|
|
URL of Snipeit system, can be set using Set-SnipeItInfo command
|
2021-05-19 15:51:49 +03:00
|
|
|
|
|
|
|
|
.PARAMETER apiKey
|
2021-05-22 18:44:36 +03:00
|
|
|
Users API Key for Snipeit, can be set using Set-SnipeItInfo command
|
2021-05-19 15:51:49 +03:00
|
|
|
|
|
|
|
|
.EXAMPLE
|
2021-05-23 23:22:23 +03:00
|
|
|
New-SnipeItAssetMaintenence -asset_id 1 -supplier_id 1 -title "replace keyboard" -start_date 2021-01-01
|
2021-05-19 15:51:49 +03:00
|
|
|
#>
|
2021-05-22 18:44:36 +03:00
|
|
|
function New-SnipeItAssetMaintenance() {
|
2018-06-23 21:18:20 +01:00
|
|
|
[CmdletBinding(
|
|
|
|
|
SupportsShouldProcess = $true,
|
|
|
|
|
ConfirmImpact = "Low"
|
|
|
|
|
)]
|
|
|
|
|
|
|
|
|
|
Param(
|
|
|
|
|
[parameter(mandatory = $true)]
|
|
|
|
|
[int]$asset_id,
|
|
|
|
|
|
|
|
|
|
[parameter(mandatory = $true)]
|
|
|
|
|
[int]$supplier_id,
|
|
|
|
|
|
|
|
|
|
[parameter(mandatory = $true)]
|
|
|
|
|
[string]$asset_maintenance_type,
|
|
|
|
|
|
|
|
|
|
[parameter(mandatory = $true)]
|
|
|
|
|
[string]$title,
|
|
|
|
|
|
|
|
|
|
[parameter(mandatory = $true)]
|
2019-04-29 14:14:33 +01:00
|
|
|
[datetime]$start_date,
|
2018-06-23 21:18:20 +01:00
|
|
|
|
|
|
|
|
[parameter(mandatory = $false)]
|
2019-04-29 14:14:33 +01:00
|
|
|
[datetime]$completion_date,
|
2018-06-23 21:18:20 +01:00
|
|
|
|
2019-04-27 20:39:05 +01:00
|
|
|
[bool]$is_warranty = $false,
|
2018-06-23 21:18:20 +01:00
|
|
|
|
|
|
|
|
[decimal]$cost,
|
|
|
|
|
|
|
|
|
|
[string]$notes,
|
|
|
|
|
|
|
|
|
|
[parameter(mandatory = $true)]
|
|
|
|
|
[string]$url,
|
|
|
|
|
|
|
|
|
|
[parameter(mandatory = $true)]
|
|
|
|
|
[string]$apiKey
|
|
|
|
|
)
|
|
|
|
|
|
2021-05-23 19:23:24 +03:00
|
|
|
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
|
|
|
|
|
2021-06-07 21:27:10 +03:00
|
|
|
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
2019-04-27 20:39:05 +01:00
|
|
|
|
|
|
|
|
if ($values['start_date']) {
|
|
|
|
|
$values['start_date'] = $values['start_date'].ToString("yyyy-MM-dd")
|
2018-06-23 21:18:20 +01:00
|
|
|
}
|
|
|
|
|
|
2019-04-29 14:14:33 +01:00
|
|
|
if ($values['completion_date']) {
|
|
|
|
|
$values['completion_date'] = $values['completion_date'].ToString("yyyy-MM-dd")
|
2019-04-27 20:39:05 +01:00
|
|
|
}
|
2018-06-23 21:18:20 +01:00
|
|
|
|
|
|
|
|
$Body = $Values | ConvertTo-Json;
|
|
|
|
|
|
|
|
|
|
$Parameters = @{
|
|
|
|
|
Uri = "$url/api/v1/maintenances"
|
|
|
|
|
Method = 'Post'
|
|
|
|
|
Body = $Body
|
|
|
|
|
Token = $apiKey
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
|
|
|
|
$result = Invoke-SnipeitMethod @Parameters
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result
|
|
|
|
|
}
|