Skip to content

Commit 1742db7

Browse files
authored
Merge pull request #129 from snazy2000/develop
Publish version 1.3
2 parents 5934568 + fca66e4 commit 1742db7

27 files changed

+803
-118
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ 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+
# [v1.3.x] - 2021-05-27
9+
10+
## Checking out accessories
11+
12+
### New features
13+
You can specify Put or Patch for Set-SnipeItAsset when updating assets.
14+
Set-SnipeItLocation new -city parameter
15+
16+
### New Functions
17+
- Set-SnipeItAccessoryOwner checkout accessory
18+
- Get-SnipeItAccessoryOwner list checkedout accessories
19+
- Reset-SnipeItAccessoryOwner checkin accessory
20+
21+
### Fixes
22+
- Set-SnipeItAsset fixed datetime and name inputs #126,128
23+
-
24+
825
# [v1.2.x] - 2021-05-24
926

1027
## Prefixing SnipeItPS

SnipeitPS/Private/Invoke-SnipeitMethod.ps1

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,32 @@
8585
Write-Verbose $webResponse.Content
8686

8787
# API returned a Content: lets work wit it
88-
$response = ConvertFrom-Json -InputObject $webResponse.Content
89-
90-
if ($response.status -eq "error") {
91-
Write-Verbose "[$($MyInvocation.MyCommand.Name)] An error response was received from; resolving"
92-
# This could be handled nicely in an function such as:
93-
# ResolveError $response -WriteError
94-
Write-Error $($response.messages | Out-String)
95-
}
96-
else {
97-
$result = $response
98-
if (($response) -and ($response | Get-Member -Name payload))
99-
{
100-
$result = $response.payload
88+
try{
89+
$response = ConvertFrom-Json -InputObject $webResponse.Content
90+
91+
if ($response.status -eq "error") {
92+
Write-Verbose "[$($MyInvocation.MyCommand.Name)] An error response was received from; resolving"
93+
# This could be handled nicely in an function such as:
94+
# ResolveError $response -WriteError
95+
Write-Error $($response.messages | Out-String)
10196
}
102-
elseif (($response) -and ($response | Get-Member -Name rows)) {
103-
$result = $response.rows
97+
else {
98+
$result = $response
99+
if (($response) -and ($response | Get-Member -Name payload))
100+
{
101+
$result = $response.payload
102+
}
103+
elseif (($response) -and ($response | Get-Member -Name rows)) {
104+
$result = $response.rows
105+
}
106+
107+
$result
104108
}
105-
106-
$result
107109
}
110+
catch {
111+
Write-Warning "Cannot parse server response. To debug try to add -Verbose with command."
112+
}
113+
108114
}
109115
elseif ($webResponse.StatusCode -eq "Unauthorized") {
110116
Write-Error "[$($MyInvocation.MyCommand.Name)] You are not Authorized to access the resource, check your token is correct"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<#
2+
.SYNOPSIS
3+
Get list of checked out accessories
4+
.DESCRIPTION
5+
Get list of checked out accessories
6+
7+
.PARAMETER id
8+
Unique ID For accessory to list
9+
10+
.PARAMETER url
11+
URL of Snipeit system, can be set using Set-SnipeItInfo command
12+
13+
.PARAMETER apiKey
14+
User's API Key for Snipeit, can be set using Set-SnipeItInfo command
15+
16+
.EXAMPLE
17+
Get-SnipeItAccessoryOwner -id 1
18+
#>
19+
function Get-SnipeItAccessoryOwner()
20+
{
21+
[CmdletBinding(
22+
SupportsShouldProcess = $true,
23+
ConfirmImpact = "Medium"
24+
)]
25+
26+
Param(
27+
[parameter(mandatory = $true)]
28+
[int]$id,
29+
30+
[parameter(mandatory = $true)]
31+
[string]$url,
32+
33+
[parameter(mandatory = $true)]
34+
[string]$apiKey
35+
)
36+
37+
$Parameters = @{
38+
Uri = "$url/api/v1/accessories/$id/checkedout"
39+
Method = 'GET'
40+
Token = $apiKey
41+
}
42+
43+
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
44+
{
45+
$result = Invoke-SnipeitMethod @Parameters
46+
}
47+
48+
return $result
49+
}

SnipeitPS/Public/New-SnipeItAsset.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function New-SnipeItAsset()
106106
[string]$purchase_cost,
107107

108108
[parameter(mandatory = $false)]
109-
[string]$purchase_date,
109+
[datetime]$purchase_date,
110110

111111
[parameter(mandatory = $false)]
112112
[int]$supplier_id,
@@ -127,6 +127,9 @@ function New-SnipeItAsset()
127127

128128
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
129129

130+
if ($values['purchase_date']) {
131+
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
132+
}
130133

131134
if ($customfields)
132135
{

SnipeitPS/Public/New-SnipeItLocation.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
.PARAMETER currency
3333
Currency used at the location
3434
35+
.PARAMETER city
36+
City of the location
37+
3538
.PARAMETER manager_id
3639
The manager ID of the location
3740
@@ -59,12 +62,16 @@ function New-SnipeItLocation() {
5962

6063
[string]$address2,
6164

65+
[string]$city,
66+
6267
[string]$state,
6368

6469
[string]$country,
6570

6671
[string]$zip,
6772

73+
[string]$currency,
74+
6875
[int]$parent_id,
6976

7077
[int]$manager_id,

SnipeitPS/Public/Remove-SnipeItAsset.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function Remove-SnipeItAsset ()
2424

2525
Param(
2626
[parameter(mandatory = $true)]
27-
[int]$ID,
27+
[int]$id,
2828
[parameter(mandatory = $true)]
2929
[string]$URL,
3030
[parameter(mandatory = $true)]
@@ -35,7 +35,7 @@ function Remove-SnipeItAsset ()
3535
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
3636

3737
$Values = @{
38-
"ID" = $Name
38+
"ID" = $id
3939
}
4040

4141
$Body = $Values | ConvertTo-Json

SnipeitPS/Public/Remove-SnipeItAssetMaintenance.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Remove-SnipeItAssetMaintenance {
2323
# Asset maintenance ID
2424
[Parameter(Mandatory = $true)]
2525
[int]
26-
$ID,
26+
$id,
2727

2828
# SnipeIt URL
2929
[Parameter(Mandatory = $true)]
@@ -39,7 +39,7 @@ function Remove-SnipeItAssetMaintenance {
3939
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
4040

4141
$Values = @{
42-
"ID" = $ID
42+
"ID" = $id
4343
}
4444

4545
$Body = $Values | ConvertTo-Json

SnipeitPS/Public/Remove-SnipeItUser.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Remove-SnipeItUser ()
2525

2626
Param(
2727
[parameter(mandatory = $true)]
28-
[string]$ID,
28+
[int]$id,
2929
[parameter(mandatory = $true)]
3030
[string]$URL,
3131
[parameter(mandatory = $true)]
@@ -36,7 +36,7 @@ function Remove-SnipeItUser ()
3636
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
3737

3838
$Values = @{
39-
"ID" = $ID
39+
"ID" = $id
4040
}
4141

4242
$Body = $Values | ConvertTo-Json
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<#
2+
.SYNOPSIS
3+
Checkin accessories
4+
5+
.DESCRIPTION
6+
Checkin accessories
7+
8+
.PARAMETER assigned_pivot_id
9+
This is the assigned_pivot_id of the accessory+user relationships in the accessories_users table
10+
Use Get-SnipeItAccessoryOwner to find out nooded value
11+
12+
.PARAMETER url
13+
URL of Snipeit system, can be set using Set-SnipeItInfo command
14+
15+
.PARAMETER apiKey
16+
User's API Key for Snipeit, can be set using Set-SnipeItInfo command
17+
18+
.EXAMPLE
19+
To get the accessories_users table for specific accessory id number
20+
21+
Get-SnipeItAccessoryOwner -id 1
22+
23+
Thenselect assigned_pivot_id for userid you like check in
24+
25+
Get-SnipeItAccessoryOwner -assigned_pivot_id xxx
26+
27+
#>
28+
function Reset-SnipeItAccessoryOwner()
29+
{
30+
[CmdletBinding(
31+
SupportsShouldProcess = $true,
32+
ConfirmImpact = "Medium"
33+
)]
34+
35+
Param(
36+
[parameter(mandatory = $true)]
37+
[int]$assigned_pivot_id,
38+
39+
[parameter(mandatory = $true)]
40+
[string]$url,
41+
42+
[parameter(mandatory = $true)]
43+
[string]$apiKey
44+
)
45+
46+
$Parameters = @{
47+
Uri = "$url/api/v1/accessories/$assigned_pivot_id/checkin"
48+
Method = 'Post'
49+
Body = '{}'
50+
Token = $apiKey
51+
}
52+
53+
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
54+
{
55+
$result = Invoke-SnipeitMethod @Parameters
56+
}
57+
58+
return $result
59+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<#
2+
.SYNOPSIS
3+
Checkout accessory
4+
.DESCRIPTION
5+
Checkout accessory to user
6+
7+
.PARAMETER id
8+
Unique ID For accessory to checkout
9+
10+
.PARAMETER assigned_id
11+
Id of target user
12+
13+
.PARAMETER note
14+
Notes about checkout
15+
16+
.PARAMETER url
17+
URL of Snipeit system, can be set using Set-SnipeItInfo command
18+
19+
.PARAMETER apiKey
20+
User's API Key for Snipeit, can be set using Set-SnipeItInfo command
21+
22+
.EXAMPLE
23+
Set-SnipeItAccessoryOwner -id 1 -assigned_id 1 -note "testing check out to user"
24+
#>
25+
function Set-SnipeItAccessoryOwner()
26+
{
27+
[CmdletBinding(
28+
SupportsShouldProcess = $true,
29+
ConfirmImpact = "Medium"
30+
)]
31+
32+
Param(
33+
[parameter(mandatory = $true)]
34+
[int]$id,
35+
36+
[parameter(mandatory = $true)]
37+
[int]$assigned_to,
38+
39+
[string] $note,
40+
41+
[parameter(mandatory = $true)]
42+
[string]$url,
43+
44+
[parameter(mandatory = $true)]
45+
[string]$apiKey
46+
)
47+
48+
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
49+
50+
$Body = $Values | ConvertTo-Json;
51+
52+
$Parameters = @{
53+
Uri = "$url/api/v1/accessories/$id/checkout"
54+
Method = 'POST'
55+
Body = $Body
56+
Token = $apiKey
57+
}
58+
59+
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
60+
{
61+
$result = Invoke-SnipeitMethod @Parameters
62+
}
63+
64+
return $result
65+
}

0 commit comments

Comments
 (0)