mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-13 18:02:30 +00:00
Added Get-AssetMaintenance and New-AssetMainteance, new isnt working currently but get works #8
This commit is contained in:
parent
54b332f2c0
commit
51bf9f43cd
3 changed files with 187 additions and 0 deletions
86
SnipeitPS/Public/Get-AssetMaintenance.ps1
Normal file
86
SnipeitPS/Public/Get-AssetMaintenance.ps1
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Gets a list of Snipe-it Assets
|
||||||
|
|
||||||
|
.PARAMETER asset_id
|
||||||
|
|
||||||
|
|
||||||
|
.PARAMETER search
|
||||||
|
A text string to search the assets data
|
||||||
|
|
||||||
|
.PARAMETER sort
|
||||||
|
Specify the column name you wish to sort by
|
||||||
|
|
||||||
|
.PARAMETER order
|
||||||
|
Specify the order (asc or desc) you wish to order by on your sort column
|
||||||
|
|
||||||
|
.PARAMETER limit
|
||||||
|
Specify the number of results you wish to return. Defaults to 50.
|
||||||
|
|
||||||
|
.PARAMETER offset
|
||||||
|
Offset to use
|
||||||
|
|
||||||
|
.PARAMETER url
|
||||||
|
URL of Snipeit system, can be set using Set-Info command
|
||||||
|
|
||||||
|
.PARAMETER apiKey
|
||||||
|
Users API Key for Snipeit, can be set using Set-Info command
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-AssetMaintenances -url "https://assets.example.com" -token "token..."
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-AssetMaintenances -search "myMachine" -url "https://assets.example.com" -token "token..."
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-AssetMaintenances -search "myMachine" -url "https://assets.example.com" -token "token..."
|
||||||
|
#>
|
||||||
|
function Get-AssetMaintenance() {
|
||||||
|
Param(
|
||||||
|
[string]$search,
|
||||||
|
|
||||||
|
[int]$asset_id,
|
||||||
|
|
||||||
|
[string]$sort = "created_at",
|
||||||
|
|
||||||
|
[ValidateSet("asc", "desc")]
|
||||||
|
[string]$order = "desc",
|
||||||
|
|
||||||
|
[int]$limit = 50,
|
||||||
|
|
||||||
|
[int]$offset,
|
||||||
|
|
||||||
|
[parameter(mandatory = $true)]
|
||||||
|
[string]$url,
|
||||||
|
|
||||||
|
[parameter(mandatory = $true)]
|
||||||
|
[string]$apiKey
|
||||||
|
)
|
||||||
|
|
||||||
|
$SearchParameter = @{
|
||||||
|
sort = $sort
|
||||||
|
order = $order
|
||||||
|
limit = $limit
|
||||||
|
offset = $offset
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
|
||||||
|
if ($PSBoundParameters.ContainsKey('asset_id')) { $SearchParameter.Add("asset_id", $asset_id) }
|
||||||
|
|
||||||
|
$Parameters = @{
|
||||||
|
Uri = "$url/api/v1/maintenances"
|
||||||
|
Method = 'Get'
|
||||||
|
GetParameters = $SearchParameter
|
||||||
|
Token = $apiKey
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = Invoke-SnipeitMethod @Parameters
|
||||||
|
|
||||||
|
$result
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
101
SnipeitPS/Public/New-AssetMaintenance.ps1
Normal file
101
SnipeitPS/Public/New-AssetMaintenance.ps1
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Add a new Asset to Snipe-it asset system
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
Long description
|
||||||
|
|
||||||
|
.PARAMETER Tag
|
||||||
|
Asset Tag for the Asset
|
||||||
|
|
||||||
|
.PARAMETER Name
|
||||||
|
Name of the Asset
|
||||||
|
|
||||||
|
.PARAMETER Status_id
|
||||||
|
Status ID of the asset, this can be got using Get-Status
|
||||||
|
|
||||||
|
.PARAMETER Model_id
|
||||||
|
Model ID of the asset, this can be got using Get-Model
|
||||||
|
|
||||||
|
.PARAMETER url
|
||||||
|
URL of Snipeit system, can be set using Set-Info command
|
||||||
|
|
||||||
|
.PARAMETER apiKey
|
||||||
|
Users API Key for Snipeit, can be set using Set-Info command
|
||||||
|
|
||||||
|
.PARAMETER customfields
|
||||||
|
Hastable of custom fields and extra fields that need passing through to Snipeit
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
New-Asset -status_id 1 -model_id 1 -name "Machine1"
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
New-Asset -status_id 1 -model_id 1 -name "Machine1" -CustomValues = @{ "_snipeit_os_5 = "Windows 10 Pro" }
|
||||||
|
#>
|
||||||
|
|
||||||
|
function New-AssetMaintenance() {
|
||||||
|
[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)]
|
||||||
|
[string]$startDate,
|
||||||
|
|
||||||
|
[parameter(mandatory = $false)]
|
||||||
|
[string]$completionDate,
|
||||||
|
|
||||||
|
[switch]$is_warranty = $false,
|
||||||
|
|
||||||
|
[decimal]$cost,
|
||||||
|
|
||||||
|
[string]$notes,
|
||||||
|
|
||||||
|
[parameter(mandatory = $true)]
|
||||||
|
[string]$url,
|
||||||
|
|
||||||
|
[parameter(mandatory = $true)]
|
||||||
|
[string]$apiKey
|
||||||
|
)
|
||||||
|
|
||||||
|
$Values = @{
|
||||||
|
"asset_id" = $asset_id
|
||||||
|
"supplier_id" = $supplier_id
|
||||||
|
"asset_maintenance_type" = $asset_maintenance_type
|
||||||
|
"title" = $title
|
||||||
|
"start_date" = $startDate
|
||||||
|
"is_warranty" = $is_warranty
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($PSBoundParameters.ContainsKey('completionDate')) { $Values.Add("completion_date", $completionDate) }
|
||||||
|
if ($PSBoundParameters.ContainsKey('cost')) { $Values.Add("cost", $cost) }
|
||||||
|
if ($PSBoundParameters.ContainsKey('notes')) { $Values.Add("notes", $notes) }
|
||||||
|
|
||||||
|
$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
|
||||||
|
}
|
||||||
Binary file not shown.
Loading…
Add table
Reference in a new issue