Skip to content

Commit ec6c96f

Browse files
authored
Merge pull request #165 from snazy2000/develop
Release 1.7
2 parents 53b1560 + 8ec56d8 commit ec6c96f

13 files changed

+1664
-3
lines changed

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/),
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8-
# [v.1.6.x]
8+
# [v.1.7.x] - 2021-06-14
9+
10+
## Consumables
11+
12+
## New features
13+
Added support for consumables
14+
15+
## New functions
16+
- New-SnipeitConsumable
17+
- Get-SnipeitConsumable
18+
- Set-SnipeitConsumable
19+
- Remove-SnipeitConsumable
20+
21+
22+
# [v.1.6.x] - 2021-06-14
923

1024
## Remove more things ja set some more
1125

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<#
2+
.SYNOPSIS
3+
Gets a list of Snipe-it consumables
4+
5+
.PARAMETER search
6+
A text string to search the consumables
7+
8+
.PARAMETER id
9+
A id of specific consumable
10+
11+
.PARAMETER company_id
12+
Id number of company
13+
14+
.PARAMETER category_id
15+
Id number of category
16+
17+
.PARAMETER manufacturer_id
18+
Id number of manufacturer
19+
20+
.PARAMETER sort
21+
Sort results by column
22+
23+
.PARAMETER order
24+
Specify the order (asc or desc) you wish to order by on your sort column
25+
26+
.PARAMETER expand
27+
Whether to include detailed information on categories, etc (true) or just the text name (false)
28+
29+
.PARAMETER limit
30+
Specify the number of results you wish to return. Defaults to 50. Defines batch size for -all
31+
32+
.PARAMETER offset
33+
Offset to use
34+
35+
.PARAMETER all
36+
A return all results
37+
38+
.PARAMETER url
39+
URL of Snipeit system,can be set using Set-SnipeitInfo command
40+
41+
.PARAMETER apiKey
42+
Users API Key for Snipeit, can be set using Set-SnipeitInfo command
43+
44+
.EXAMPLE
45+
Get-SnipeitConsumable -all
46+
Returns all consumables
47+
48+
.EXAMPLE
49+
Get-SnipeitConsumable -search paper
50+
Returns search results containeing string display
51+
52+
.EXAMPLE
53+
Get-Snipeitconsumable -id
54+
Returns specific consumable
55+
56+
#>
57+
function Get-SnipeitConsumable() {
58+
[CmdletBinding(DefaultParameterSetName = 'Search')]
59+
Param(
60+
[parameter(ParameterSetName='Search')]
61+
[string]$search,
62+
63+
[parameter(ParameterSetName='Get with ID')]
64+
[int[]]$id,
65+
66+
[parameter(ParameterSetName='Search')]
67+
[int]$category_id,
68+
69+
[parameter(ParameterSetName='Search')]
70+
[int]$company_id,
71+
72+
[parameter(ParameterSetName='Search')]
73+
[int]$manufacturer_id,
74+
75+
[parameter(ParameterSetName='Search')]
76+
[int]$location_id,
77+
78+
[parameter(ParameterSetName='Search')]
79+
[ValidateSet("asc", "desc")]
80+
[string]$order = "desc",
81+
82+
[parameter(ParameterSetName='Search')]
83+
[ValidateSet('id', 'name', 'min_amt', 'order_number', 'serial', 'purchase_date', 'purchase_cost', 'company', 'category', 'qty', 'location', 'image', 'created_at')]
84+
[string]$sort = "created_at",
85+
86+
87+
[Parameter(ParameterSetName='Search')]
88+
[switch]$expand,
89+
90+
[parameter(ParameterSetName='Search')]
91+
[int]$limit = 50,
92+
93+
[parameter(ParameterSetName='Search')]
94+
[int]$offset,
95+
96+
[parameter(ParameterSetName='Search')]
97+
[switch]$all = $false,
98+
99+
[parameter(mandatory = $true)]
100+
[string]$url,
101+
102+
[parameter(mandatory = $true)]
103+
[string]$apiKey
104+
)
105+
begin {
106+
107+
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
108+
}
109+
110+
process {
111+
switch ($PSCmdlet.ParameterSetName) {
112+
'Search' {
113+
$Parameters = @{
114+
Uri = "$url/api/v1/consumables"
115+
Method = 'Get'
116+
Token = $apiKey
117+
GetParameters = $SearchParameter
118+
}
119+
120+
if ($all) {
121+
$offstart = $(if($offset){$offset} Else {0})
122+
$callargs = $SearchParameter
123+
$callargs.Remove('all')
124+
125+
while ($true) {
126+
$callargs['offset'] = $offstart
127+
$callargs['limit'] = $limit
128+
$res=Get-Snipeitconsumable @callargs
129+
$res
130+
if ($res.count -ne $limit) {
131+
break
132+
}
133+
$offstart = $offstart + $limit
134+
}
135+
} else {
136+
$result = Invoke-SnipeitMethod @Parameters
137+
$result
138+
}
139+
}
140+
141+
'Get with ID' {
142+
foreach($consumable_id in $id) {
143+
$Parameters = @{
144+
Uri = "$url/api/v1/consumables/$consumable_id"
145+
Method = 'Get'
146+
Token = $apiKey
147+
GetParameters = $SearchParameter
148+
}
149+
$result = Invoke-SnipeitMethod @Parameters
150+
$result
151+
}
152+
}
153+
}
154+
}
155+
}
156+
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<#
2+
.SYNOPSIS
3+
Add a new Consumable to Snipe-it asset system
4+
5+
.DESCRIPTION
6+
Long description
7+
8+
.PARAMETER name
9+
Required Name of the Consumable
10+
11+
.PARAMETER qty
12+
Required Quantity of comsumable
13+
14+
.PARAMETER category_id
15+
Required Category ID of the Consumable, this can be got using Get-SnipeitCategory
16+
17+
.PARAMETER min_amt
18+
Optional minimum quantity of comsumable
19+
20+
.PARAMETER company_id
21+
Optional Company id
22+
23+
.PARAMETER order_number
24+
Optional Order number
25+
26+
.PARAMETER manufacturer_id
27+
Manufaturer id number of the consumable
28+
29+
.PARAMETER location_id
30+
Location id number of the consumable
31+
32+
.PARAMETER requestable
33+
Is consumable requestable?
34+
35+
.PARAMETER purchase_date
36+
Optional Purchase cost of the consumable
37+
38+
.PARAMETER purchase_cost
39+
Optional Purchase cost of the consumable
40+
41+
.PARAMETER model_number
42+
Model number of the consumable in months
43+
44+
.PARAMETER item_no
45+
Item number for the consumable
46+
47+
.PARAMETER url
48+
URL of Snipeit system, can be set using Set-SnipeitInfo command
49+
50+
.PARAMETER apiKey
51+
Users API Key for Snipeit, can be set using Set-SnipeitInfo command
52+
53+
54+
.EXAMPLE
55+
New-Snipeitconsumable -name "Ink pack" -qty 20 -category_id 3 -min_amt 5
56+
Create consumable with stock count 20 , alert when stock is 5 or lower
57+
58+
#>
59+
60+
function New-SnipeitConsumable()
61+
{
62+
[CmdletBinding(
63+
SupportsShouldProcess = $true,
64+
ConfirmImpact = "Low"
65+
)]
66+
67+
Param(
68+
[parameter(mandatory = $true)]
69+
[string]$name,
70+
71+
[parameter(mandatory = $true)]
72+
[int]$qty,
73+
74+
[parameter(mandatory = $true)]
75+
[int]$category_id,
76+
77+
[parameter(mandatory = $false)]
78+
[int]$min_amt,
79+
80+
[parameter(mandatory = $false)]
81+
[int]$company_id,
82+
83+
[parameter(mandatory = $false)]
84+
[string]$order_number,
85+
86+
[parameter(mandatory = $false)]
87+
[int]$manufacturer_id,
88+
89+
[parameter(mandatory = $false)]
90+
[int]$location_id,
91+
92+
[parameter(mandatory = $false)]
93+
[bool]$requestable,
94+
95+
[parameter(mandatory = $false)]
96+
[datetime]$purchase_date,
97+
98+
[parameter(mandatory = $false)]
99+
[string]$purchase_cost,
100+
101+
[parameter(mandatory = $false)]
102+
[string]$model_number,
103+
104+
[parameter(mandatory = $false)]
105+
[string]$item_no,
106+
107+
[parameter(mandatory = $true)]
108+
[string]$url,
109+
110+
[parameter(mandatory = $true)]
111+
[string]$apiKey
112+
113+
)
114+
begin {
115+
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
116+
117+
if ($values['purchase_date']) {
118+
$Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd")
119+
}
120+
121+
$Body = $Values | ConvertTo-Json;
122+
}
123+
124+
process {
125+
$Parameters = @{
126+
Uri = "$url/api/v1/consumables"
127+
Method = 'Post'
128+
Body = $Body
129+
Token = $apiKey
130+
}
131+
132+
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
133+
{
134+
$result = Invoke-SnipeitMethod @Parameters
135+
}
136+
137+
$result
138+
}
139+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<#
2+
.SYNOPSIS
3+
Removes consumable from Snipe-it asset system
4+
.DESCRIPTION
5+
Removes consumable or multiple consumables from Snipe-it asset system
6+
.PARAMETER ID
7+
Unique ID For consumable to be removed
8+
9+
.PARAMETER url
10+
URL of Snipeit system, can be set using Set-SnipeitInfo command
11+
12+
.PARAMETER apiKey
13+
User's API Key for Snipeit, can be set using Set-SnipeitInfo command
14+
15+
.EXAMPLE
16+
Remove-SnipeitConsumable -ID 44 -Verbose
17+
18+
.EXAMPLE
19+
Get-SnipeitConsumable -search "paper" | Remove-Snipeitconsumable
20+
#>
21+
22+
function Remove-SnipeitConsumable ()
23+
{
24+
[CmdletBinding(
25+
SupportsShouldProcess = $true,
26+
ConfirmImpact = "Low"
27+
)]
28+
29+
Param(
30+
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
31+
[int[]]$id,
32+
[parameter(mandatory = $true)]
33+
[string]$URL,
34+
[parameter(mandatory = $true)]
35+
[string]$APIKey
36+
37+
)
38+
begin {
39+
}
40+
process {
41+
foreach($consumable_id in $id){
42+
$Parameters = @{
43+
Uri = "$url/api/v1/consumables/$consumable_id"
44+
Method = 'Delete'
45+
Body = '{}'
46+
Token = $apiKey
47+
}
48+
49+
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
50+
{
51+
$result = Invoke-SnipeitMethod @Parameters
52+
}
53+
$result
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)