Skip to content

Commit

Permalink
Merge pull request #160 from snazy2000/develop
Browse files Browse the repository at this point in the history
Publish v.1.6
  • Loading branch information
PetriAsi authored Jun 13, 2021
2 parents a69a583 + 9d5c3e7 commit 53b1560
Show file tree
Hide file tree
Showing 54 changed files with 4,316 additions and 211 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/),
and this project adheres to [Semantic Versioning](http://semver.org/).

# [v.1.6.x]

## Remove more things ja set some more

### New features
Added some set and remove functions. Pipelineinput supported
for all remove functions.

### New functions
- Remove-SnipeitAccessory
- Remove-SnipeitCategory
- Remove-SnipeitCompany
- Remove-SnipeitComponent
- Remove-SnipeitCustomField
- Remove-SnipeitDepartment
- Remove-SnipeitLicense
- Remove-SnipeitLocation
- Remove-SnipeitManufacturer
- Remove-SnipeitModel
- Set-SnipeitCategory
- Set-SnipeitCompany
- Set-SnipeitCustomField
- Set-SnipeitDepartment
- Set-SnipeitStatus


# [v1.5.x] - 2021-06-08

## Piping input
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Set-SnipeitInfo -URL 'https://asset.example.com' -apiKey 'tokenKey'

```powershell
# Review the help at any time!
Get-Help about_SnipeitPS
Get-Command -Module SnipeitPS
Get-Help Get-SnipeitAsset -Full # or any other command
```
Expand Down
71 changes: 35 additions & 36 deletions SnipeitPS/Public/New-SnipeitCategory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ Name of new category to be created
.PARAMETER type
Type of new category to be created (asset, accessory, consumable, component, license)
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfo command
.PARAMETER apiKey
User's API Key for Snipeit, can be set using Set-SnipeitInfo command
.PARAMETER eula_text
This allows you to customize your EULAs for specific types of assets
.PARAMETER use_default_eula
If switch is present, use the primary default EULA
Expand All @@ -23,6 +20,12 @@ If switch is present, require users to confirm acceptance of assets in this cate
.PARAMETER checkin_email
If switch is present, send email to user on checkin/checkout
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfo command
.PARAMETER apiKey
User's API Key for Snipeit, can be set using Set-SnipeitInfo command
.EXAMPLE
New-SnipeitCategory -name "Laptops" -category_type asset -url "Snipe-IT URL here..." -apiKey "API key here..."
#>
Expand All @@ -42,51 +45,47 @@ function New-SnipeitCategory()
[ValidateSet("asset", "accessory", "consumable", "component", "license")]
[string]$category_type,

[parameter(mandatory = $true)]
[string]$url,
[string]$eula_text,

[parameter(mandatory = $true)]
[string]$apiKey,

[switch]$use_default_eula,

[switch]$require_acceptance,

[switch]$checkin_email
)
[switch]$checkin_email,
[parameter(mandatory = $true)]
[string]$url,

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

$Values = @{
"name" = $name
"category_type" = $category_type
}
)
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name

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

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

if ($checkin_email) {
$Values += @{"checkin_email" = $true}
$Body = $Values | ConvertTo-Json;
}

$Body = $Values | ConvertTo-Json;
process {

$Parameters = @{
Uri = "$url/api/v1/categories"
Method = 'POST'
Body = $Body
Token = $apiKey
}
$Parameters = @{
Uri = "$url/api/v1/categories"
Method = 'POST'
Body = $Body
Token = $apiKey
}

If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}

$result
$result
}
}
80 changes: 58 additions & 22 deletions SnipeitPS/Public/New-SnipeitCustomField.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,29 @@
.DESCRIPTION
Add a new Custom Field to Snipe-it asset system
.PARAMETER Name
Name of the Custom Field
.PARAMETER name
The field's name, which is also the form label
.PARAMETER element
Form field type that should be displayed.
.PARAMETER field_values
In the case of list boxes, etc, this should be a list of the options available
.PARAMETER show_in_email
Whether or not to show the custom field in email notifications
.PARAMETER format
How the field should be validated
.PARAMETER custom_format
In the case of format 'CUSTOM REGEX', this should be validation regex this field
.PARAMETER field_encrypted
Whether the field should be encrypted. (This can cause issues if you change it after the field was created.)
.PARAMETER help_text
Any additional text you wish to display under the new form field to make it clearer what the gauges should be.
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfo command
Expand All @@ -27,17 +48,25 @@ function New-SnipeitCustomField()

Param(
[parameter(mandatory = $true)]
[string]$Name,
[string]$name,

[string]$HelpText,
[string]$help_text,

[string]$Element = "text",
[parameter(mandatory = $true)]
[ValidateSet('text','textarea','listbox','checkbox','radio')]
[string]$element ,

[parameter(mandatory = $true)]
[ValidateSet('ANY','CUSTOM REGEX','ALPHA','ALPHA-DASH','NUMERIC','ALPHA-NUMERIC','EMAIL','DATE','URL','IP','IPV4','IPV6','MAC','BOOLEAN')]
[string]$format,

[string]$field_values,

[string]$Format = "ANY",
[bool]$field_encrypted=$false,

[bool]$field_encrypted,
[bool]$show_in_email=$false,

[string]$CustomFormat,
[string]$custom_format,

[parameter(mandatory = $true)]
[string]$url,
Expand All @@ -46,24 +75,31 @@ function New-SnipeitCustomField()
[string]$apiKey
)

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

$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters

#Convert Values to JSON format
$Body = $Values | ConvertTo-Json;
$Body = $Values | ConvertTo-Json;

$Parameters = @{
Uri = "$url/api/v1/fields"
Method = 'post'
Body = $Body
Token = $apiKey
$Parameters = @{
Uri = "$url/api/v1/fields"
Method = 'post'
Body = $Body
Token = $apiKey
}
}

If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
process{
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}

$result
$result
}
}

55 changes: 55 additions & 0 deletions SnipeitPS/Public/Remove-SnipeitAccessory.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<#
.SYNOPSIS
Removes Accessory from Snipe-it asset system
.DESCRIPTION
Removes Accessory or multiple Accessoriers from Snipe-it asset system
.PARAMETER ID
Unique ID For accessory to be removed
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfo command
.PARAMETER apiKey
User's API Key for Snipeit, can be set using Set-SnipeitInfo command
.EXAMPLE
Remove-SnipeitAccessory -ID 44 -Verbose
.EXAMPLE
Get-SnipeitAccessory -search needle | Remove-SnipeitAccessory
#>

function Remove-SnipeitAccessory ()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]

Param(
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[parameter(mandatory = $true)]
[string]$URL,
[parameter(mandatory = $true)]
[string]$APIKey

)
begin {
}
process {
foreach($accessory_id in $id){
$Parameters = @{
Uri = "$url/api/v1/accessories/$accessory_id"
Method = 'Delete'
Body = '{}'
Token = $apiKey
}

If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
}
46 changes: 23 additions & 23 deletions SnipeitPS/Public/Remove-SnipeitAsset.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.SYNOPSIS
Removes Asset from Snipe-it asset system
.DESCRIPTION
Removes Asset from Snipe-it asset system
Removes asset or multiple assets from Snipe-it asset system
.PARAMETER ID
Unique ID For Asset to be removed
.PARAMETER url
Expand All @@ -13,6 +13,9 @@
.EXAMPLE
Remove-SnipeitAsset -ID 44 -Verbose
.EXAMPLE
Get-SnipeitAsset -serial 123456789 | Remove-SnipeitAsset
#>

function Remove-SnipeitAsset ()
Expand All @@ -23,34 +26,31 @@ function Remove-SnipeitAsset ()
)]

Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[parameter(mandatory = $true)]
[string]$URL,
[parameter(mandatory = $true)]
[string]$APIKey

)

Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name

$Values = @{
"ID" = $id
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
}

$Body = $Values | ConvertTo-Json

$Parameters = @{
Uri = "$url/api/v1/hardware/$ID"
Method = 'Delete'
Body = $Body
Token = $apiKey
process {
foreach($asset_id in $id){
$Parameters = @{
Uri = "$url/api/v1/hardware/$asset_id"
Method = 'Delete'
Body = '{}'
Token = $apiKey
}

If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}

If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}

$result
}
Loading

0 comments on commit 53b1560

Please sign in to comment.