Added more commands and changed way parameters work, also added more parameters to bring it inline with recent api changed

This commit is contained in:
Stephen Maunder 2019-04-27 20:39:05 +01:00
parent 4f22833342
commit 56852d863e
28 changed files with 501 additions and 233 deletions

View file

@ -1,4 +1,5 @@
function ConvertTo-GetParameter {
<#
.SYNOPSIS
Generate the GET parameter string for an URL from a hashtable
@ -14,6 +15,8 @@ function ConvertTo-GetParameter {
}
PROCESS {
Add-Type -AssemblyName System.Web
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Making HTTP get parameter string out of a hashtable"
foreach ($key in $InputObject.Keys) {
$parameters += "$key=$([System.Web.HttpUtility]::UrlEncode($InputObject[$key]))&"

View file

@ -0,0 +1,59 @@
function Get-ParameterValue {
#.Synopsis
# Get the actual values of parameters which have manually set (non-null) default values or values passed in the call
#.Description
# Unlike $PSBoundParameters, the hashtable returned from Get-ParameterValues includes non-empty default parameter values.
# NOTE: Default values that are the same as the implied values are ignored (e.g.: empty strings, zero numbers, nulls).
#.Example
# function Test-Parameters {
# [CmdletBinding()]
# param(
# $Name = $Env:UserName,
# $Age
# )
# $Parameters = . Get-ParameterValues
#
# # This WILL ALWAYS have a value...
# Write-Host $Parameters["Name"]
#
# # But this will NOT always have a value...
# Write-Host $PSBoundParameters["Name"]
# }
[CmdletBinding()]
param(
# The $MyInvocation for the caller -- DO NOT pass this (dot-source Get-ParameterValues instead)
$Invocation = $MyInvocation,
# The $PSBoundParameters for the caller -- DO NOT pass this (dot-source Get-ParameterValues instead)
$BoundParameters = $PSBoundParameters,
[string[]]$DefaultExcludeParameter = @("id", "url", "apiKey", 'Debug', 'Verbose')
)
if ($MyInvocation.Line[($MyInvocation.OffsetInLine - 1)] -ne '.') {
throw "Get-ParameterValues must be dot-sourced, like this: . Get-ParameterValues"
}
if ($PSBoundParameters.Count -gt 0) {
throw "You should not pass parameters to Get-ParameterValues, just dot-source it like this: . Get-ParameterValues"
}
$ParameterValues = @{}
foreach ($parameter in $Invocation.MyCommand.Parameters.GetEnumerator()) {
# gm -in $parameter.Value | Out-Default
try {
$key = $parameter.Key
if ($key -notin $DefaultExcludeParameter) {
if ($null -ne ($value = Get-Variable -Name $key -ValueOnly -ErrorAction Ignore )) {
if ($value -ne ($null -as $parameter.Value.ParameterType)) {
$ParameterValues[$key] = $value
}
}
if ($BoundParameters.ContainsKey($key)) {
$ParameterValues[$key] = $BoundParameters[$key]
}
}
}
finally {}
}
return $ParameterValues
}

View file

@ -0,0 +1,47 @@
function Get-Accessory() {
Param(
[string]$search,
[int]$company_id,
[int]$category_id,
[int]$manufacturer_id,
[int]$supplier_id,
[string]$sort = "created_at",
[ValidateSet("asc", "desc")]
[string]$order = "desc",
[int]$limit = 50,
[int]$offset,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/accessories"
Method = 'Get'
GetParameters = $SearchParameter
Token = $apiKey
}
$result = Invoke-SnipeitMethod @Parameters
$result
}

View file

@ -51,7 +51,10 @@ Users API Key for Snipeit, can be set using Set-Info command
Get-Asset -url "https://assets.example.com" -token "token..."
.EXAMPLE
Get-Asset -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "MyMachine" }
Get-Asset -search "myMachine" -url "https://assets.example.com" -token "token..."
.EXAMPLE
Get-Asset -search "myMachine" -url "https://assets.example.com" -token "token..."
#>
function Get-Asset() {
Param(
@ -69,6 +72,10 @@ function Get-Asset() {
[int]$location_id,
[int]$depreciation_id,
[bool]$requestable = $false,
[string]$status,
[int]$status_id,
@ -89,23 +96,7 @@ function Get-Asset() {
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) }
if ($PSBoundParameters.ContainsKey('model_id')) { $SearchParameter.Add("model_id", $model_id) }
if ($PSBoundParameters.ContainsKey('category_id')) { $SearchParameter.Add("category_id", $category_id) }
if ($PSBoundParameters.ContainsKey('manufacturer_id')) { $SearchParameter.Add("manufacturer_id", $manufacturer_id) }
if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) }
if ($PSBoundParameters.ContainsKey('location_id')) { $SearchParameter.Add("location_id", $location_id) }
if ($PSBoundParameters.ContainsKey('status_id')) { $SearchParameter.Add("status_id", $order_number) }
if ($PSBoundParameters.ContainsKey('status')) { $SearchParameter.Add("status", $order_number) }
if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/hardware"

View file

@ -57,15 +57,7 @@ function Get-AssetMaintenance() {
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
if ($PSBoundParameters.ContainsKey('asset_id')) { $SearchParameter.Add("asset_id", $asset_id) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/maintenances"

View file

@ -35,14 +35,7 @@ function Get-Category()
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/categories"

View file

@ -35,14 +35,7 @@ function Get-Company()
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/companies"

View file

@ -24,9 +24,14 @@ function Get-Component() {
[int]$company_id,
[int]$location_id,
[ValidateSet("asc", "desc")]
[string]$order = "desc",
[ValidateSet('id', 'name', 'min_amt', 'order_number', 'serial', 'purchase_date', 'purchase_cost', 'company', 'category', 'qty', 'location', 'image', 'created_at')]
[string]$sort = "created_at",
[int]$limit = 50,
[int]$offset,
@ -38,16 +43,7 @@ function Get-Component() {
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
if ($PSBoundParameters.ContainsKey('category_id')) { $SearchParameter.Add("category_id", $category_id) }
if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/components"

View file

@ -28,6 +28,9 @@ function Get-Department()
[int]$offset,
[ValidateSet('id', 'name', 'image', 'users_count', 'created_at')]
[string]$sort = "created_at",
[parameter(mandatory = $true)]
[string]$url,
@ -35,14 +38,7 @@ function Get-Department()
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/departments"

View file

@ -32,7 +32,7 @@ function Get-License() {
[string]$license_name,
[string]$license_email,
[mailaddress]$license_email,
[int]$manufacturer_id,
@ -40,9 +40,14 @@ function Get-License() {
[int]$depreciation_id,
[int]$category_id,
[ValidateSet("asc", "desc")]
[string]$order = "desc",
[ValidateSet('id', 'name', 'purchase_cost', 'expiration_date', 'purchase_order', 'order_number', 'notes', 'purchase_date', 'serial', 'company', 'category', 'license_name', 'license_email', 'free_seats_count', 'seats', 'manufacturer', 'supplier')]
[string]$sort = "created_at",
[int]$limit = 50,
[int]$offset,
@ -54,24 +59,7 @@ function Get-License() {
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
if ($PSBoundParameters.ContainsKey('name')) { $SearchParameter.Add("name", $name) }
if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) }
if ($PSBoundParameters.ContainsKey('product_key')) { $SearchParameter.Add("product_key", $product_key) }
if ($PSBoundParameters.ContainsKey('order_number')) { $SearchParameter.Add("order_number", $order_number) }
if ($PSBoundParameters.ContainsKey('purchase_order')) { $SearchParameter.Add("purchase_order", $purchase_order) }
if ($PSBoundParameters.ContainsKey('license_name')) { $SearchParameter.Add("license_name", $license_name) }
if ($PSBoundParameters.ContainsKey('license_email')) { $SearchParameter.Add("license_email", $license_email) }
if ($PSBoundParameters.ContainsKey('manufacturer_id')) { $SearchParameter.Add("manufacturer_id", $manufacturer_id) }
if ($PSBoundParameters.ContainsKey('supplier_id')) { $SearchParameter.Add("supplier_id", $supplier_id) }
if ($PSBoundParameters.ContainsKey('depreciation_id')) { $SearchParameter.Add("depreciation_id", $depreciation_id) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/licenses"

View file

@ -35,14 +35,7 @@ function Get-Location()
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/locations"

View file

@ -35,14 +35,7 @@ function Get-Manufacturer()
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/manufacturers"

View file

@ -35,14 +35,7 @@ function Get-Model()
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/models"

View file

@ -35,14 +35,7 @@ function Get-Status()
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/statuslabels"

View file

@ -35,14 +35,7 @@ function Get-Supplier()
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/suppliers"

View file

@ -41,18 +41,7 @@ function Get-User() {
[string]$apiKey
)
$SearchParameter = @{
sort = $sort
order = $order
limit = $limit
offset = $offset
}
if ($PSBoundParameters.ContainsKey('search')) { $SearchParameter.Add("search", $search) }
if ($PSBoundParameters.ContainsKey('company_id')) { $SearchParameter.Add("company_id", $company_id) }
if ($PSBoundParameters.ContainsKey('location_id')) { $SearchParameter.Add("location_id", $location_id) }
if ($PSBoundParameters.ContainsKey('group_id')) { $SearchParameter.Add("group_id", $group_id) }
if ($PSBoundParameters.ContainsKey('department_id')) { $SearchParameter.Add("department_id", $department_id) }
$SearchParameter = . Get-ParameterValue
$Parameters = @{
Uri = "$url/api/v1/users"

View file

@ -0,0 +1,65 @@
function New-Accessory() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[ValidateLength(3, 255)]
[string]$name,
[parameter(mandatory = $true)]
[int]$qty,
[parameter(mandatory = $true)]
[ValidateRange(1, [int]::MaxValue)]
[int]$category_id,
[ValidateRange(1, [int]::MaxValue)]
[int]$company_id,
[ValidateRange(1, [int]::MaxValue)]
[int]$manufacturer_id,
[string]$order_number,
[float]$purchase_cost,
[datetime]$purchase_date,
[bool]$requestable,
[ValidateRange(1, [int]::MaxValue)]
[int]$supplier_id,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = . Get-ParameterValue
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/accessories"
Method = 'POST'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

View file

@ -58,7 +58,7 @@ function New-AssetMaintenance() {
[parameter(mandatory = $false)]
[datetime]$completionDate,
[switch]$is_warranty=$false,
[bool]$is_warranty = $false,
[decimal]$cost,
@ -71,18 +71,15 @@ function New-AssetMaintenance() {
[string]$apiKey
)
$Values = @{
"asset_id" = $asset_id
"supplier_id" = $supplier_id
"asset_maintenance_type" = $asset_maintenance_type
"title" = $title
"start_date" = $startDate.ToString("yyyy-MM-dd")
"is_warranty" = [Bool]::Parse($is_warranty)
$Values = . Get-ParameterValue
if ($values['start_date']) {
$values['start_date'] = $values['start_date'].ToString("yyyy-MM-dd")
}
if ($PSBoundParameters.ContainsKey('completionDate')) { $Values.Add("completion_date", $completionDate.ToString("yyyy-MM-dd")) }
if ($PSBoundParameters.ContainsKey('cost')) { $Values.Add("cost", $cost) }
if ($PSBoundParameters.ContainsKey('notes')) { $Values.Add("notes", $notes) }
if ($values['completionDate']) {
$values['completionDate'] = $values['completionDate'].ToString("yyyy-MM-dd")
}
$Body = $Values | ConvertTo-Json;

View file

@ -39,9 +39,7 @@ function New-Company()
[string]$apiKey
)
$Values = @{
"name" = $name
}
$Values = . Get-ParameterValue
$Body = $Values | ConvertTo-Json;

View file

@ -27,8 +27,7 @@
General notes
#>
function New-Component()
{
function New-Component() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
@ -39,11 +38,19 @@ function New-Component()
[string]$name,
[parameter(mandatory = $true)]
[string]$category_id,
[int]$category_id,
[parameter(mandatory = $true)]
[string]$qty,
[int]$company_id,
[int]$location_id,
[datetime]$purchase_date,
[float]$purchase_cost,
[parameter(mandatory = $true)]
[string]$url,
@ -51,10 +58,10 @@ function New-Component()
[string]$apiKey
)
$Values = @{
"name" = $name
"category_id" = $category_id
"qty" = $qty
$Values = . Get-ParameterValue
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
$Body = $Values | ConvertTo-Json;
@ -66,8 +73,7 @@ function New-Component()
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}

View file

@ -35,6 +35,8 @@ function New-CustomField()
[string]$Format = "ANY",
[bool]$field_encrypted,
[string]$CustomFormat,
[parameter(mandatory = $true)]
@ -44,14 +46,7 @@ function New-CustomField()
[string]$apiKey
)
$Values = @{
"name" = $Name
"help_text" = $HelpText
"element" = $Element
"format" = $Format
"custom_format" = $CustomFormat
}
$Values = . Get-ParameterValue
#Convert Values to JSON format
$Body = $Values | ConvertTo-Json;

View file

@ -27,8 +27,7 @@
General notes
#>
function New-Department()
{
function New-Department() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
@ -38,11 +37,13 @@ function New-Department()
[parameter(mandatory = $true)]
[string]$name,
[string]$company_id,
[int]$company_id,
[string]$location_id,
[int]$location_id,
[string]$manager_id,
[int]$manager_id,
[string]$notes,
[parameter(mandatory = $true)]
[string]$url,
@ -51,12 +52,7 @@ function New-Department()
[string]$apiKey
)
$Values = @{
"name" = $name
"company_id" = $company_id
"location_id" = $location_id
"manager_id" = $manager_id
}
$Values = . Get-ParameterValue
$Body = $Values | ConvertTo-Json;
@ -67,8 +63,7 @@ function New-Department()
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}

View file

@ -0,0 +1,88 @@
function New-License() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[ValidateLength(3, 255)]
[string]$name,
[parameter(mandatory = $true)]
[int]$seats,
[ValidateRange(1, [int]::MaxValue)]
[int]$category_id,
[ValidateRange(1, [int]::MaxValue)]
[int]$company_id,
[datetime]$expiration_date,
[ValidateLength(1, 120)]
[mailaddress]$license_email,
[ValidateLength(1, 100)]
[string]$license_name,
[bool]$maintained,
[ValidateRange(1, [int]::MaxValue)]
[int]$manufacturer_id,
[string]$notes,
[string]$order_number,
[float]$purchase_cost,
[datetime]$purchase_date,
[bool]$reassignable,
[string]$serial,
[ValidateRange(1, [int]::MaxValue)]
[int]$supplier_id,
[datetime]$termination_date,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = . Get-ParameterValue
if ($values['expiration_date']) {
$values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd")
}
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
if ($values['termination_date']) {
$values['termination_date'] = $values['termination_date'].ToString("yyyy-MM-dd")
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/licenses"
Method = 'POST'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

View file

@ -47,6 +47,10 @@ function New-Location() {
[string]$zip,
[int]$manager_id,
[string]$ldap_ou,
[parameter(mandatory = $true)]
[string]$url,
@ -54,14 +58,7 @@ function New-Location() {
[string]$apiKey
)
$Values = @{
name = $name
address = $address
address2 = $address2
state = $state
country = $country
zip = $zip
}
$Values = . Get-ParameterValue
$Body = $Values | ConvertTo-Json;

View file

@ -0,0 +1,65 @@
function Set-Accessory() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[ValidateLength(3, 255)]
[string]$name,
[int]$qty,
[ValidateRange(1, [int]::MaxValue)]
[int]$category_id,
[ValidateRange(1, [int]::MaxValue)]
[int]$company_id,
[ValidateRange(1, [int]::MaxValue)]
[int]$manufacturer_id,
[string]$order_number,
[float]$purchase_cost,
[datetime]$purchase_date,
[bool]$requestable,
[ValidateRange(1, [int]::MaxValue)]
[int]$supplier_id,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = . Get-ParameterValue
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/accessories/$id"
Method = 'POST'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

View file

@ -0,0 +1,90 @@
function Set-License() {
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[ValidateLength(3, 255)]
[string]$name,
[ValidateRange(1, [int]::MaxValue)]
[int]$seats,
[ValidateRange(1, [int]::MaxValue)]
[int]$category_id,
[ValidateRange(1, [int]::MaxValue)]
[int]$company_id,
[datetime]$expiration_date,
[ValidateLength(1, 120)]
[mailaddress]$license_email,
[ValidateLength(1, 100)]
[string]$license_name,
[bool]$maintained,
[ValidateRange(1, [int]::MaxValue)]
[int]$manufacturer_id,
[string]$notes,
[string]$order_number,
[float]$purchase_cost,
[datetime]$purchase_date,
[bool]$reassignable,
[string]$serial,
[ValidateRange(1, [int]::MaxValue)]
[int]$supplier_id,
[datetime]$termination_date,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = . Get-ParameterValue
if ($values['expiration_date']) {
$values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd")
}
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
if ($values['termination_date']) {
$values['termination_date'] = $values['termination_date'].ToString("yyyy-MM-dd")
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/licenses/$id"
Method = 'PUT'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

View file

@ -1,38 +1,3 @@
<#
.SYNOPSIS
Updates a Model within the Snipe-it asset system
.DESCRIPTION
Long description
.PARAMETER name
Name of the Asset Model
.PARAMETER model_number
Part or model number of the model
.PARAMETER category_id
Category ID that the asset belongs to this can be got using Get-Category
.PARAMETER manufacturer_id
Manufacturer ID that the asset belongs to this can be got using Get-Manufacturer
.PARAMETER eol
Number of months until this model's assets are considered EOL
.PARAMETER fieldset_id
Fieldset ID that the asset uses (Custom fields)
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE
New-Model -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1
#>
function Set-Model() {
[CmdletBinding(
SupportsShouldProcess = $true,
@ -41,20 +6,23 @@ function Set-Model() {
Param(
[parameter(mandatory = $true)]
[int]$id,
[ValidateLength(1, 255)]
[string]$name,
[ValidateLength(1, 255)]
[string]$model_number,
[parameter(mandatory = $true)]
[int]$category_id,
[parameter(mandatory = $true)]
[int]$manufacturer_id,
[ValidateRange(1, 240)]
[int]$eol,
[parameter(mandatory = $true)]
[int]$fieldset_id,
[Alias("fieldset_id")]
[int]$custom_fieldset_id,
[parameter(mandatory = $true)]
[string]$url,
@ -63,20 +31,12 @@ function Set-Model() {
[string]$apiKey
)
$Values = @{
name = $name
category_id = $category_id
manufacturer_id = $manufacturer_id
fieldset_id = $fieldset_id
}
if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) }
if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) }
$Values = Copy-Parameters -InputObject $PSBoundParameters
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/models"
Uri = "$url/api/v1/models/$id"
Method = 'put'
Body = $Body
Token = $apiKey

Binary file not shown.