Skip to content

Commit b967ebb

Browse files
authored
Merge pull request #11 from snazy2000/develop
Added Get-AssetMaintenance and New-AssetMainteance, new isnt working…
2 parents 864ff91 + 51bf9f4 commit b967ebb

File tree

3 files changed

+187
-0
lines changed

3 files changed

+187
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<#
2+
.SYNOPSIS
3+
Gets a list of Snipe-it Assets
4+
5+
.PARAMETER asset_id
6+
7+
8+
.PARAMETER search
9+
A text string to search the assets data
10+
11+
.PARAMETER sort
12+
Specify the column name you wish to sort by
13+
14+
.PARAMETER order
15+
Specify the order (asc or desc) you wish to order by on your sort column
16+
17+
.PARAMETER limit
18+
Specify the number of results you wish to return. Defaults to 50.
19+
20+
.PARAMETER offset
21+
Offset to use
22+
23+
.PARAMETER url
24+
URL of Snipeit system, can be set using Set-Info command
25+
26+
.PARAMETER apiKey
27+
Users API Key for Snipeit, can be set using Set-Info command
28+
29+
.EXAMPLE
30+
Get-AssetMaintenances -url "https://assets.example.com" -token "token..."
31+
32+
.EXAMPLE
33+
Get-AssetMaintenances -search "myMachine" -url "https://assets.example.com" -token "token..."
34+
35+
.EXAMPLE
36+
Get-AssetMaintenances -search "myMachine" -url "https://assets.example.com" -token "token..."
37+
#>
38+
function Get-AssetMaintenance() {
39+
Param(
40+
[string]$search,
41+
42+
[int]$asset_id,
43+
44+
[string]$sort = "created_at",
45+
46+
[ValidateSet("asc", "desc")]
47+
[string]$order = "desc",
48+
49+
[int]$limit = 50,
50+
51+
[int]$offset,
52+
53+
[parameter(mandatory = $true)]
54+
[string]$url,
55+
56+
[parameter(mandatory = $true)]
57+
[string]$apiKey
58+
)
59+
60+
$SearchParameter = @{
61+
sort = $sort
62+
order = $order
63+
limit = $limit
64+
offset = $offset
65+
}
66+
67+
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
68+
if ($PSBoundParameters.ContainsKey('asset_id')) { $SearchParameter.Add("asset_id", $asset_id) }
69+
70+
$Parameters = @{
71+
Uri = "$url/api/v1/maintenances"
72+
Method = 'Get'
73+
GetParameters = $SearchParameter
74+
Token = $apiKey
75+
}
76+
77+
$result = Invoke-SnipeitMethod @Parameters
78+
79+
$result
80+
}
81+
82+
83+
84+
85+
86+
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<#
2+
.SYNOPSIS
3+
Add a new Asset to Snipe-it asset system
4+
5+
.DESCRIPTION
6+
Long description
7+
8+
.PARAMETER Tag
9+
Asset Tag for the Asset
10+
11+
.PARAMETER Name
12+
Name of the Asset
13+
14+
.PARAMETER Status_id
15+
Status ID of the asset, this can be got using Get-Status
16+
17+
.PARAMETER Model_id
18+
Model ID of the asset, this can be got using Get-Model
19+
20+
.PARAMETER url
21+
URL of Snipeit system, can be set using Set-Info command
22+
23+
.PARAMETER apiKey
24+
Users API Key for Snipeit, can be set using Set-Info command
25+
26+
.PARAMETER customfields
27+
Hastable of custom fields and extra fields that need passing through to Snipeit
28+
29+
.EXAMPLE
30+
New-Asset -status_id 1 -model_id 1 -name "Machine1"
31+
32+
.EXAMPLE
33+
New-Asset -status_id 1 -model_id 1 -name "Machine1" -CustomValues = @{ "_snipeit_os_5 = "Windows 10 Pro" }
34+
#>
35+
36+
function New-AssetMaintenance() {
37+
[CmdletBinding(
38+
SupportsShouldProcess = $true,
39+
ConfirmImpact = "Low"
40+
)]
41+
42+
Param(
43+
[parameter(mandatory = $true)]
44+
[int]$asset_id,
45+
46+
[parameter(mandatory = $true)]
47+
[int]$supplier_id,
48+
49+
[parameter(mandatory = $true)]
50+
[string]$asset_maintenance_type,
51+
52+
[parameter(mandatory = $true)]
53+
[string]$title,
54+
55+
[parameter(mandatory = $true)]
56+
[string]$startDate,
57+
58+
[parameter(mandatory = $false)]
59+
[string]$completionDate,
60+
61+
[switch]$is_warranty = $false,
62+
63+
[decimal]$cost,
64+
65+
[string]$notes,
66+
67+
[parameter(mandatory = $true)]
68+
[string]$url,
69+
70+
[parameter(mandatory = $true)]
71+
[string]$apiKey
72+
)
73+
74+
$Values = @{
75+
"asset_id" = $asset_id
76+
"supplier_id" = $supplier_id
77+
"asset_maintenance_type" = $asset_maintenance_type
78+
"title" = $title
79+
"start_date" = $startDate
80+
"is_warranty" = $is_warranty
81+
}
82+
83+
if ($PSBoundParameters.ContainsKey('completionDate')) { $Values.Add("completion_date", $completionDate) }
84+
if ($PSBoundParameters.ContainsKey('cost')) { $Values.Add("cost", $cost) }
85+
if ($PSBoundParameters.ContainsKey('notes')) { $Values.Add("notes", $notes) }
86+
87+
$Body = $Values | ConvertTo-Json;
88+
89+
$Parameters = @{
90+
Uri = "$url/api/v1/maintenances"
91+
Method = 'Post'
92+
Body = $Body
93+
Token = $apiKey
94+
}
95+
96+
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
97+
$result = Invoke-SnipeitMethod @Parameters
98+
}
99+
100+
$result
101+
}

SnipeitPS/SnipeItPS.psd1

132 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)