SnipeitPS/SnipeitPS/Public/New-SnipeItCategory.ps1

93 lines
2.1 KiB
PowerShell
Raw Normal View History

2020-06-29 18:50:43 -05:00
<#
.SYNOPSIS
2021-05-19 15:51:49 +03:00
Create a new Snipe-IT Category
2020-06-29 18:50:43 -05:00
.PARAMETER name
Name of new category to be created
2021-05-19 15:51:49 +03:00
2020-06-29 18:50:43 -05:00
.PARAMETER type
2020-06-29 19:42:05 -05:00
Type of new category to be created (asset, accessory, consumable, component, license)
2021-05-19 15:51:49 +03:00
2020-06-29 18:50:43 -05:00
.PARAMETER url
URL of Snipeit system, can be set using Set-SnipeItInfo command
2021-05-19 15:51:49 +03:00
2020-06-29 18:50:43 -05:00
.PARAMETER apiKey
User's API Key for Snipeit, can be set using Set-SnipeItInfo command
2021-05-19 15:51:49 +03:00
2020-06-29 18:50:43 -05:00
.PARAMETER use_default_eula
If switch is present, use the primary default EULA
2021-05-19 15:51:49 +03:00
2020-06-29 18:50:43 -05:00
.PARAMETER require_acceptance
If switch is present, require users to confirm acceptance of assets in this category
2021-05-19 15:51:49 +03:00
2020-06-29 18:50:43 -05:00
.PARAMETER checkin_email
If switch is present, send email to user on checkin/checkout
2021-05-19 15:51:49 +03:00
2020-06-29 18:50:43 -05:00
.EXAMPLE
2021-05-23 23:22:23 +03:00
New-SnipeItCategory -name "Laptops" -category_type asset -url "Snipe-IT URL here..." -apiKey "API key here..."
2020-06-29 18:50:43 -05:00
#>
function New-SnipeItCategory()
2020-06-29 18:50:43 -05:00
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[string]$name,
[parameter(mandatory = $true)]
2020-06-29 19:42:05 -05:00
[ValidateSet("asset", "accessory", "consumable", "component", "license")]
2020-06-29 18:50:43 -05:00
[string]$category_type,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey,
[switch]$use_default_eula,
[switch]$require_acceptance,
[switch]$checkin_email
)
2021-05-23 19:23:24 +03:00
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = @{
"name" = $name
"category_type" = $category_type
}
2020-06-29 20:26:45 -05:00
2020-06-29 18:50:43 -05:00
if ($use_default_eula) {
$Values += @{"use_default_eula" = $true}
2020-06-29 18:50:43 -05:00
}
if ($require_acceptance) {
$Values += @{"require_acceptance" = $true}
2020-06-29 18:50:43 -05:00
}
if ($checkin_email) {
$Values += @{"checkin_email" = $true}
2020-06-29 18:50:43 -05:00
}
2021-05-17 10:07:17 +03:00
2020-06-29 18:50:43 -05:00
$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
}