Merge pull request #159 from PetriAsi/feature/set-things

Set thing and couple other fixes
This commit is contained in:
Petri Asikainen 2021-06-13 18:57:17 +03:00 committed by GitHub
commit 7d6aa54279
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 594 additions and 111 deletions

View file

@ -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
@ -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..."
#>
@ -42,39 +45,34 @@ 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,
[parameter(mandatory = $true)]
[string]$apiKey
)
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = @{
"name" = $name
"category_type" = $category_type
if($eula_text -and $use_default_eula){
throw 'Dont use -use_defalt_eula if -eula_text is set'
}
if ($use_default_eula) {
$Values += @{"use_default_eula" = $true}
}
if ($require_acceptance) {
$Values += @{"require_acceptance" = $true}
}
if ($checkin_email) {
$Values += @{"checkin_email" = $true}
}
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
}
process {
$Parameters = @{
Uri = "$url/api/v1/categories"
@ -90,3 +88,4 @@ function New-SnipeitCategory()
$result
}
}

View file

@ -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
@ -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 ,
[string]$Format = "ANY",
[parameter(mandatory = $true)]
[ValidateSet('ANY','CUSTOM REGEX','ALPHA','ALPHA-DASH','NUMERIC','ALPHA-NUMERIC','EMAIL','DATE','URL','IP','IPV4','IPV6','MAC','BOOLEAN')]
[string]$format,
[bool]$field_encrypted,
[string]$field_values,
[string]$CustomFormat,
[bool]$field_encrypted=$false,
[bool]$show_in_email=$false,
[string]$custom_format,
[parameter(mandatory = $true)]
[string]$url,
@ -46,11 +75,14 @@ function New-SnipeitCustomField()
[string]$apiKey
)
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
#Convert Values to JSON format
$Body = $Values | ConvertTo-Json;
$Parameters = @{
@ -59,7 +91,9 @@ function New-SnipeitCustomField()
Body = $Body
Token = $apiKey
}
}
process{
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
@ -67,3 +101,5 @@ function New-SnipeitCustomField()
$result
}
}

View file

@ -2,10 +2,13 @@ function Remove-SnipeitAssetMaintenance {
<#
.SYNOPSIS
Remove asset maintenance from Snipe-it asset system
.DESCRIPTION
Removes asset maintenance event or events from Snipe-it asset system by ID
.PARAMETER ID
Unique ID of the asset maintenance to be removed
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfoeItInfo command

View file

@ -18,7 +18,7 @@
Get-SnipeitCategory -search something | Remove-SnipeitCategory
#>
function Remove-SnipeitModel ()
function Remove-SnipeitCategory ()
{
[CmdletBinding(
SupportsShouldProcess = $true,

View file

@ -37,7 +37,7 @@ function Remove-SnipeitDepartment ()
begin {
}
process {
foreach($depatment_id in $id){
foreach($department_id in $id){
$Parameters = @{
Uri = "$url/api/v1/departments/$department_id"
Method = 'Delete'

View file

@ -0,0 +1,90 @@
<#
.SYNOPSIS
Create a new Snipe-IT Category
.PARAMETER name
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 use_default_eula
If switch is present, use the primary default EULA
.PARAMETER eula_text
This allows you to customize your EULAs for specific types of assets
.PARAMETER require_acceptance
If switch is present, require users to confirm acceptance of assets in this category
.PARAMETER checkin_email
Should the user be emailed the EULA and/or an acceptance confirmation email when this item is checked in?
.EXAMPLE
Set-SnipeitCategory -id 4 -name "Laptops"
#>
function Set-SnipeitCategory()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[int[]]$id,
[string]$name,
[ValidateSet("asset", "accessory", "consumable", "component", "license")]
[string]$category_type,
[string]$eula_text,
[bool]$use_default_eula,
[bool]$require_acceptance,
[bool]$checkin_email,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
}
process {
foreach($category_id in $id){
$Parameters = @{
Uri = "$url/api/v1/categories/$category_id"
Method = 'Put'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
}

View file

@ -0,0 +1,70 @@
<#
.SYNOPSIS
Updates company name
.DESCRIPTION
Updates companyt name on Snipe-It system
.PARAMETER id
ID number of company
.PARAMETER name
Company name
.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
An example
.NOTES
General notes
#>
function Set-SnipeitCompany()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Medium"
)]
Param(
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[parameter(mandatory = $true)]
[string]$name,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
begin{
$values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $values | ConvertTo-Json;
}
process{
foreach($company_id in $id){
$Parameters = @{
Uri = "$url/api/v1/companies/$company_id"
Method = 'Patch'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
}

View file

@ -49,8 +49,8 @@ function Set-SnipeitComponent()
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[parameter(mandatory = $true)]
[int]$qty,
@ -74,7 +74,7 @@ function Set-SnipeitComponent()
[parameter(mandatory = $true)]
[string]$apiKey
)
begin {
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
@ -84,9 +84,12 @@ function Set-SnipeitComponent()
}
$Body = $values | ConvertTo-Json;
}
process {
foreach($component_id in $id){
$Parameters = @{
Uri = "$url/api/v1/components/$id"
Uri = "$url/api/v1/components/$component_id"
Method = 'Patch'
Body = $Body
Token = $apiKey
@ -99,3 +102,5 @@ function Set-SnipeitComponent()
$result
}
}
}

View file

@ -0,0 +1,108 @@
<#
.SYNOPSIS
Add a new Custom Field to Snipe-it asset system
.DESCRIPTION
Add a new Custom Field to Snipe-it asset system
.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
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-SnipeitInfo command
.EXAMPLE
New-SnipeitCustomField -Name "AntivirusInstalled" -Format "BOOLEAN" -HelpText "Is AntiVirus installed on Asset"
#>
function Set-SnipeitCustomField()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[string]$name,
[string]$help_text,
[parameter(Mandatory=$true)]
[ValidateSet('text','textarea','listbox','checkbox','radio')]
[string]$element ,
[ValidateSet('ANY','CUSTOM REGEX','ALPHA','ALPHA-DASH','NUMERIC','ALPHA-NUMERIC','EMAIL','DATE','URL','IP','IPV4','IPV6','MAC','BOOLEAN')]
[string]$format,
[string]$field_values,
[bool]$field_encrypted,
[bool]$show_in_email,
[string]$custom_format,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
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
$Body = $Values | ConvertTo-Json;
}
process{
foreach($field_id in $id) {
$Parameters = @{
Uri = "$url/api/v1/fields/$field_id"
Method = 'Put'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
}

View file

@ -0,0 +1,85 @@
<#
.SYNOPSIS
Updates a department
.DESCRIPTION
Updates the department on Snipe-It system
.PARAMETER id
Id number of Department
.PARAMETER name
Department Name
.PARAMETER company_id
ID number of company
.PARAMETER location_id
ID number of location
.PARAMETER manager_id
ID number of manager
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfo command
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-SnipeitInfo command
.EXAMPLE
Set-SnipeitDepartment -id 4 -manager_id 3
#>
function Set-SnipeitDepartment() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[string]$name,
[int]$company_id,
[int]$location_id,
[int]$manager_id,
[string]$notes,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
begin {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
}
process {
foreach ($department_id in $id) {
$Parameters = @{
Uri = "$url/api/v1/departments/$department_id"
Method = 'Put'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
}

View file

@ -129,6 +129,7 @@ function Set-SnipeitLicense() {
[parameter(mandatory = $true)]
[string]$apiKey
)
begin{
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
@ -148,6 +149,7 @@ function Set-SnipeitLicense() {
$Body = $Values | ConvertTo-Json;
}
process {
foreach($license_id in $id){
$Parameters = @{

View file

@ -0,0 +1,83 @@
<#
.SYNOPSIS
Sets Snipe-it Status Labels
.PARAMETER id
A id of specific Status Label
.PARAMETER color
Hex code showing what color the status label should be on the pie chart in the dashboard
.PARAMETER show_in_nav
1 or 0 - determine whether the status label should show in the left-side nav of the web GUI
.PARAMETER default_label
1 or 0 - determine whether it should be bubbled up to the top of the list of available statuses
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfo command
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-SnipeitInfo command
.EXAMPLE
Get-SnipeitStatus -search "Ready to Deploy"
.EXAMPLE
Set-SnipeitStatus -id 3 -name 'Waiting for arrival' -type pending
#>
function Set-SnipeitStatus()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Medium"
)]
Param(
[parameter(Mandatory=$true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[string]$name,
[parameter(Mandatory=$true)]
[ValidateSet('deployable','undeployable','pending','archived')]
[string]$type,
[string]$notes,
[string]$color,
[bool]$show_in_nav,
[bool]$default_label,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
begin {
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json
}
process {
foreach($status_id in $id) {
$Parameters = @{
Uri = "$url/api/v1/statuslabels/$status_id"
Method = 'Put'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
}

View file

@ -80,13 +80,10 @@ function Set-SnipeitUser() {
[string]$userName,
[string]$jobtitle,
[string]$email,
[string]$phone,
[int]$company_id,
@ -97,12 +94,10 @@ function Set-SnipeitUser() {
[int]$manager_id,
[string]$employee_num,
[bool]$activated,
[string]$notes,
[parameter(mandatory = $true)]

View file

@ -70,6 +70,9 @@ PowerShellVersion = '3.0'
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @(
'Get-SnipeitAccessory',
'Get-SnipeitAccessoryOwner',
'Get-SnipeitActivity',
'Get-SnipeitAsset',
'Get-SnipeitAssetMaintenance',
'Get-SnipeitCategory',
@ -78,45 +81,30 @@ FunctionsToExport = @(
'Get-SnipeitCustomField',
'Get-SnipeitDepartment',
'Get-SnipeitFieldset',
'Get-SnipeitLicense',
'Get-SnipeitLicenseSeat',
'Get-SnipeitLocation',
'Get-SnipeitManufacturer',
'Get-SnipeitModel',
'Get-SnipeitStatus',
'Get-SnipeitSupplier',
'Get-SnipeitUser',
'New-SnipeitAccessory',
'New-SnipeitAsset',
'New-SnipeitAssetMaintenance',
'New-SnipeItAudit',
'New-SnipeitCategory',
'New-SnipeitComponent',
'New-SnipeitCustomField',
'New-SnipeitDepartment',
'New-SnipeitLicense',
'Set-SnipeitLicense',
'Get-SnipeitLicense',
'Get-SnipeitLicenseSeat',
'Set-SnipeitLicenseSeat',
'New-SnipeitLocation',
'New-SnipeitManufacturer',
'New-SnipeitModel',
'New-SnipeitUser',
'Set-SnipeitAsset',
'Set-SnipeitAssetOwner',
'Set-SnipeitComponent',
'Set-SnipeitModel',
'Set-SnipeitInfo',
'Set-SnipeitUser',
'Set-SnipeitLocation',
'Add-SnipeitAccessory',
'Set-SnipeitAccessory',
'Get-SnipeitAccessory',
'Remove-SnipeitAsset',
'Remove-SnipeitUser',
'Update-SnipeitAlias',
'Set-SnipeitAccessoryOwner',
'Get-SnipeitAccessoryOwner',
'Reset-SnipeitAccessoryOwner',
'Get-SnipeitActivity',
'Remove-SnipeitAccessory',
'Remove-SnipeitAsset',
'Remove-SnipeitAssetMaintenance',
'Remove-SnipeitCategory',
'Remove-SnipeitCompany',
'Remove-SnipeitComponent',
@ -125,8 +113,27 @@ FunctionsToExport = @(
'Remove-SnipeitLicense',
'Remove-SnipeitLocation',
'Remove-SnipeitManufacturer',
'Remove-SnipeitModel'
'Remove-SnipeitModel',
'Remove-SnipeitUser',
'Reset-SnipeitAccessoryOwner',
'Reset-SnipeitAssetOwner',
'Set-SnipeitAccessory',
'Set-SnipeitAccessoryOwner',
'Set-SnipeitAsset',
'Set-SnipeitAssetOwner',
'Set-SnipeitCategory'
'Set-SnipeitCompany'
'Set-SnipeitComponent',
'Set-SnipeitCustomField',
'Set-SnipeitDepartment',
'Set-SnipeitInfo',
'Set-SnipeitLicense',
'Set-SnipeitLicenseSeat',
'Set-SnipeitLocation',
'Set-SnipeitModel',
'Set-SnipeitStatus',
'Set-SnipeitUser',
'Update-SnipeitAlias'
)
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.