mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-13 18:02:30 +00:00
manage categories
This commit is contained in:
parent
b495032167
commit
ac842e3d6a
3 changed files with 130 additions and 41 deletions
|
|
@ -8,11 +8,8 @@ Name of new category to be created
|
||||||
.PARAMETER type
|
.PARAMETER type
|
||||||
Type of new category to be created (asset, accessory, consumable, component, license)
|
Type of new category to be created (asset, accessory, consumable, component, license)
|
||||||
|
|
||||||
.PARAMETER url
|
.PARAMETER eula_text
|
||||||
URL of Snipeit system, can be set using Set-SnipeitInfo command
|
This allows you to customize your EULAs for specific types of assets
|
||||||
|
|
||||||
.PARAMETER apiKey
|
|
||||||
User's API Key for Snipeit, can be set using Set-SnipeitInfo command
|
|
||||||
|
|
||||||
.PARAMETER use_default_eula
|
.PARAMETER use_default_eula
|
||||||
If switch is present, use the primary 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
|
.PARAMETER checkin_email
|
||||||
If switch is present, send email to user on checkin/checkout
|
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
|
.EXAMPLE
|
||||||
New-SnipeitCategory -name "Laptops" -category_type asset -url "Snipe-IT URL here..." -apiKey "API key here..."
|
New-SnipeitCategory -name "Laptops" -category_type asset -url "Snipe-IT URL here..." -apiKey "API key here..."
|
||||||
#>
|
#>
|
||||||
|
|
@ -42,51 +45,47 @@ function New-SnipeitCategory()
|
||||||
[ValidateSet("asset", "accessory", "consumable", "component", "license")]
|
[ValidateSet("asset", "accessory", "consumable", "component", "license")]
|
||||||
[string]$category_type,
|
[string]$category_type,
|
||||||
|
|
||||||
[parameter(mandatory = $true)]
|
[string]$eula_text,
|
||||||
[string]$url,
|
|
||||||
|
|
||||||
[parameter(mandatory = $true)]
|
|
||||||
[string]$apiKey,
|
|
||||||
|
|
||||||
[switch]$use_default_eula,
|
[switch]$use_default_eula,
|
||||||
|
|
||||||
[switch]$require_acceptance,
|
[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
|
||||||
|
|
||||||
Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
|
if($eula_text -and $use_default_eula){
|
||||||
|
throw 'Dont use -use_defalt_eula if -eula_text is set'
|
||||||
|
}
|
||||||
|
|
||||||
$Values = @{
|
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
|
||||||
"name" = $name
|
|
||||||
"category_type" = $category_type
|
$Body = $Values | ConvertTo-Json;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($use_default_eula) {
|
process {
|
||||||
$Values += @{"use_default_eula" = $true}
|
|
||||||
|
$Parameters = @{
|
||||||
|
Uri = "$url/api/v1/categories"
|
||||||
|
Method = 'POST'
|
||||||
|
Body = $Body
|
||||||
|
Token = $apiKey
|
||||||
|
}
|
||||||
|
|
||||||
|
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
||||||
|
{
|
||||||
|
$result = Invoke-SnipeitMethod @Parameters
|
||||||
|
}
|
||||||
|
|
||||||
|
$result
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($require_acceptance) {
|
|
||||||
$Values += @{"require_acceptance" = $true}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($checkin_email) {
|
|
||||||
$Values += @{"checkin_email" = $true}
|
|
||||||
}
|
|
||||||
|
|
||||||
$Body = $Values | ConvertTo-Json;
|
|
||||||
|
|
||||||
$Parameters = @{
|
|
||||||
Uri = "$url/api/v1/categories"
|
|
||||||
Method = 'POST'
|
|
||||||
Body = $Body
|
|
||||||
Token = $apiKey
|
|
||||||
}
|
|
||||||
|
|
||||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
|
||||||
{
|
|
||||||
$result = Invoke-SnipeitMethod @Parameters
|
|
||||||
}
|
|
||||||
|
|
||||||
$result
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
Get-SnipeitCategory -search something | Remove-SnipeitCategory
|
Get-SnipeitCategory -search something | Remove-SnipeitCategory
|
||||||
#>
|
#>
|
||||||
|
|
||||||
function Remove-SnipeitModel ()
|
function Remove-SnipeitCategory ()
|
||||||
{
|
{
|
||||||
[CmdletBinding(
|
[CmdletBinding(
|
||||||
SupportsShouldProcess = $true,
|
SupportsShouldProcess = $true,
|
||||||
|
|
|
||||||
90
SnipeitPS/Public/Set-SnipeitCategory.ps1
Normal file
90
SnipeitPS/Public/Set-SnipeitCategory.ps1
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue