Skip to content

Commit 53b1560

Browse files
authored
Merge pull request #160 from snazy2000/develop
Publish v.1.6
2 parents a69a583 + 9d5c3e7 commit 53b1560

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4316
-211
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@ 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]
9+
10+
## Remove more things ja set some more
11+
12+
### New features
13+
Added some set and remove functions. Pipelineinput supported
14+
for all remove functions.
15+
16+
### New functions
17+
- Remove-SnipeitAccessory
18+
- Remove-SnipeitCategory
19+
- Remove-SnipeitCompany
20+
- Remove-SnipeitComponent
21+
- Remove-SnipeitCustomField
22+
- Remove-SnipeitDepartment
23+
- Remove-SnipeitLicense
24+
- Remove-SnipeitLocation
25+
- Remove-SnipeitManufacturer
26+
- Remove-SnipeitModel
27+
- Set-SnipeitCategory
28+
- Set-SnipeitCompany
29+
- Set-SnipeitCustomField
30+
- Set-SnipeitDepartment
31+
- Set-SnipeitStatus
32+
33+
834
# [v1.5.x] - 2021-06-08
935

1036
## Piping input

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Set-SnipeitInfo -URL 'https://asset.example.com' -apiKey 'tokenKey'
2828

2929
```powershell
3030
# Review the help at any time!
31+
Get-Help about_SnipeitPS
3132
Get-Command -Module SnipeitPS
3233
Get-Help Get-SnipeitAsset -Full # or any other command
3334
```

SnipeitPS/Public/New-SnipeitCategory.ps1

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ Name of new category to be created
88
.PARAMETER type
99
Type of new category to be created (asset, accessory, consumable, component, license)
1010
11-
.PARAMETER url
12-
URL of Snipeit system, can be set using Set-SnipeitInfo command
13-
14-
.PARAMETER apiKey
15-
User's API Key for Snipeit, can be set using Set-SnipeitInfo command
11+
.PARAMETER eula_text
12+
This allows you to customize your EULAs for specific types of assets
1613
1714
.PARAMETER use_default_eula
1815
If switch is present, use the primary default EULA
@@ -23,6 +20,12 @@ If switch is present, require users to confirm acceptance of assets in this cate
2320
.PARAMETER checkin_email
2421
If switch is present, send email to user on checkin/checkout
2522
23+
.PARAMETER url
24+
URL of Snipeit system, can be set using Set-SnipeitInfo command
25+
26+
.PARAMETER apiKey
27+
User's API Key for Snipeit, can be set using Set-SnipeitInfo command
28+
2629
.EXAMPLE
2730
New-SnipeitCategory -name "Laptops" -category_type asset -url "Snipe-IT URL here..." -apiKey "API key here..."
2831
#>
@@ -42,51 +45,47 @@ function New-SnipeitCategory()
4245
[ValidateSet("asset", "accessory", "consumable", "component", "license")]
4346
[string]$category_type,
4447

45-
[parameter(mandatory = $true)]
46-
[string]$url,
48+
[string]$eula_text,
4749

48-
[parameter(mandatory = $true)]
49-
[string]$apiKey,
5050

5151
[switch]$use_default_eula,
5252

5353
[switch]$require_acceptance,
5454

55-
[switch]$checkin_email
56-
)
55+
[switch]$checkin_email,
56+
[parameter(mandatory = $true)]
57+
[string]$url,
5758

58-
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
59+
[parameter(mandatory = $true)]
60+
[string]$apiKey
5961

60-
$Values = @{
61-
"name" = $name
62-
"category_type" = $category_type
63-
}
62+
)
63+
begin {
64+
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
6465

65-
if ($use_default_eula) {
66-
$Values += @{"use_default_eula" = $true}
67-
}
66+
if($eula_text -and $use_default_eula){
67+
throw 'Dont use -use_defalt_eula if -eula_text is set'
68+
}
6869

69-
if ($require_acceptance) {
70-
$Values += @{"require_acceptance" = $true}
71-
}
70+
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
7271

73-
if ($checkin_email) {
74-
$Values += @{"checkin_email" = $true}
72+
$Body = $Values | ConvertTo-Json;
7573
}
7674

77-
$Body = $Values | ConvertTo-Json;
75+
process {
7876

79-
$Parameters = @{
80-
Uri = "$url/api/v1/categories"
81-
Method = 'POST'
82-
Body = $Body
83-
Token = $apiKey
84-
}
77+
$Parameters = @{
78+
Uri = "$url/api/v1/categories"
79+
Method = 'POST'
80+
Body = $Body
81+
Token = $apiKey
82+
}
8583

86-
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
87-
{
88-
$result = Invoke-SnipeitMethod @Parameters
89-
}
84+
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
85+
{
86+
$result = Invoke-SnipeitMethod @Parameters
87+
}
9088

91-
$result
89+
$result
90+
}
9291
}

SnipeitPS/Public/New-SnipeitCustomField.ps1

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,29 @@
55
.DESCRIPTION
66
Add a new Custom Field to Snipe-it asset system
77
8-
.PARAMETER Name
9-
Name of the Custom Field
8+
.PARAMETER name
9+
The field's name, which is also the form label
10+
11+
.PARAMETER element
12+
Form field type that should be displayed.
13+
14+
.PARAMETER field_values
15+
In the case of list boxes, etc, this should be a list of the options available
16+
17+
.PARAMETER show_in_email
18+
Whether or not to show the custom field in email notifications
19+
20+
.PARAMETER format
21+
How the field should be validated
22+
23+
.PARAMETER custom_format
24+
In the case of format 'CUSTOM REGEX', this should be validation regex this field
25+
26+
.PARAMETER field_encrypted
27+
Whether the field should be encrypted. (This can cause issues if you change it after the field was created.)
28+
29+
.PARAMETER help_text
30+
Any additional text you wish to display under the new form field to make it clearer what the gauges should be.
1031
1132
.PARAMETER url
1233
URL of Snipeit system, can be set using Set-SnipeitInfo command
@@ -27,17 +48,25 @@ function New-SnipeitCustomField()
2748

2849
Param(
2950
[parameter(mandatory = $true)]
30-
[string]$Name,
51+
[string]$name,
3152

32-
[string]$HelpText,
53+
[string]$help_text,
3354

34-
[string]$Element = "text",
55+
[parameter(mandatory = $true)]
56+
[ValidateSet('text','textarea','listbox','checkbox','radio')]
57+
[string]$element ,
58+
59+
[parameter(mandatory = $true)]
60+
[ValidateSet('ANY','CUSTOM REGEX','ALPHA','ALPHA-DASH','NUMERIC','ALPHA-NUMERIC','EMAIL','DATE','URL','IP','IPV4','IPV6','MAC','BOOLEAN')]
61+
[string]$format,
62+
63+
[string]$field_values,
3564

36-
[string]$Format = "ANY",
65+
[bool]$field_encrypted=$false,
3766

38-
[bool]$field_encrypted,
67+
[bool]$show_in_email=$false,
3968

40-
[string]$CustomFormat,
69+
[string]$custom_format,
4170

4271
[parameter(mandatory = $true)]
4372
[string]$url,
@@ -46,24 +75,31 @@ function New-SnipeitCustomField()
4675
[string]$apiKey
4776
)
4877

49-
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
78+
begin {
79+
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
80+
if ($format -eq 'CUSTOM REGEX' -and (-not $custom_format)) {
81+
throw "Please specify regex validation with -custom_format when using -format 'CUSTOM REGEX'"
82+
}
5083

51-
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
84+
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
5285

53-
#Convert Values to JSON format
54-
$Body = $Values | ConvertTo-Json;
86+
$Body = $Values | ConvertTo-Json;
5587

56-
$Parameters = @{
57-
Uri = "$url/api/v1/fields"
58-
Method = 'post'
59-
Body = $Body
60-
Token = $apiKey
88+
$Parameters = @{
89+
Uri = "$url/api/v1/fields"
90+
Method = 'post'
91+
Body = $Body
92+
Token = $apiKey
93+
}
6194
}
6295

63-
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
64-
{
65-
$result = Invoke-SnipeitMethod @Parameters
66-
}
96+
process{
97+
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
98+
{
99+
$result = Invoke-SnipeitMethod @Parameters
100+
}
67101

68-
$result
102+
$result
103+
}
69104
}
105+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<#
2+
.SYNOPSIS
3+
Removes Accessory from Snipe-it asset system
4+
.DESCRIPTION
5+
Removes Accessory or multiple Accessoriers from Snipe-it asset system
6+
.PARAMETER ID
7+
Unique ID For accessory to be removed
8+
.PARAMETER url
9+
URL of Snipeit system, can be set using Set-SnipeitInfo command
10+
11+
.PARAMETER apiKey
12+
User's API Key for Snipeit, can be set using Set-SnipeitInfo command
13+
14+
.EXAMPLE
15+
Remove-SnipeitAccessory -ID 44 -Verbose
16+
17+
.EXAMPLE
18+
Get-SnipeitAccessory -search needle | Remove-SnipeitAccessory
19+
#>
20+
21+
function Remove-SnipeitAccessory ()
22+
{
23+
[CmdletBinding(
24+
SupportsShouldProcess = $true,
25+
ConfirmImpact = "Low"
26+
)]
27+
28+
Param(
29+
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
30+
[int[]]$id,
31+
[parameter(mandatory = $true)]
32+
[string]$URL,
33+
[parameter(mandatory = $true)]
34+
[string]$APIKey
35+
36+
)
37+
begin {
38+
}
39+
process {
40+
foreach($accessory_id in $id){
41+
$Parameters = @{
42+
Uri = "$url/api/v1/accessories/$accessory_id"
43+
Method = 'Delete'
44+
Body = '{}'
45+
Token = $apiKey
46+
}
47+
48+
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
49+
{
50+
$result = Invoke-SnipeitMethod @Parameters
51+
}
52+
$result
53+
}
54+
}
55+
}

SnipeitPS/Public/Remove-SnipeitAsset.ps1

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.SYNOPSIS
33
Removes Asset from Snipe-it asset system
44
.DESCRIPTION
5-
Removes Asset from Snipe-it asset system
5+
Removes asset or multiple assets from Snipe-it asset system
66
.PARAMETER ID
77
Unique ID For Asset to be removed
88
.PARAMETER url
@@ -13,6 +13,9 @@
1313
1414
.EXAMPLE
1515
Remove-SnipeitAsset -ID 44 -Verbose
16+
17+
.EXAMPLE
18+
Get-SnipeitAsset -serial 123456789 | Remove-SnipeitAsset
1619
#>
1720

1821
function Remove-SnipeitAsset ()
@@ -23,34 +26,31 @@ function Remove-SnipeitAsset ()
2326
)]
2427

2528
Param(
26-
[parameter(mandatory = $true)]
27-
[int]$id,
29+
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
30+
[int[]]$id,
2831
[parameter(mandatory = $true)]
2932
[string]$URL,
3033
[parameter(mandatory = $true)]
3134
[string]$APIKey
3235

3336
)
34-
35-
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
36-
37-
$Values = @{
38-
"ID" = $id
37+
begin {
38+
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
3939
}
40-
41-
$Body = $Values | ConvertTo-Json
42-
43-
$Parameters = @{
44-
Uri = "$url/api/v1/hardware/$ID"
45-
Method = 'Delete'
46-
Body = $Body
47-
Token = $apiKey
40+
process {
41+
foreach($asset_id in $id){
42+
$Parameters = @{
43+
Uri = "$url/api/v1/hardware/$asset_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+
}
4855
}
49-
50-
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
51-
{
52-
$result = Invoke-SnipeitMethod @Parameters
53-
}
54-
55-
$result
5656
}

0 commit comments

Comments
 (0)