mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-13 18:02:30 +00:00
commit
29345d496d
10 changed files with 255 additions and 10 deletions
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
---
|
||||
|
||||
## Want to say thanks?
|
||||
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XP29MAD7P3WDN&source=url)
|
||||
|
||||
## Instructions
|
||||
|
||||
### Installation
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@ function ConvertTo-GetParameter {
|
|||
PROCESS {
|
||||
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Making HTTP get parameter string out of a hashtable"
|
||||
foreach ($key in $InputObject.Keys) {
|
||||
$parameters += "$key=$($InputObject[$key])&"
|
||||
$parameters += "$key=$([System.Web.HttpUtility]::UrlEncode($InputObject[$key]))&"
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
$parameters -replace ".$"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
35
SnipeitPS/Public/Get-CustomField.ps1
Normal file
35
SnipeitPS/Public/Get-CustomField.ps1
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
# Returns a list of all Snipe-IT 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
|
||||
Get-Field -url "https://assets.example.com" -token "token..."
|
||||
|
||||
#>
|
||||
|
||||
function Get-CustomField()
|
||||
{
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/fields"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
37
SnipeitPS/Public/Get-Fieldset.ps1
Normal file
37
SnipeitPS/Public/Get-Fieldset.ps1
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
# Gets a list of Snipe-it Fieldsets
|
||||
|
||||
.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
|
||||
Get-Fieldset -url "https://assets.example.com" -token "token..."
|
||||
|
||||
.EXAMPLE
|
||||
Get-Fieldset -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Windows" }
|
||||
|
||||
#>
|
||||
|
||||
function Get-Fieldset() {
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/fieldsets"
|
||||
Method = 'Get'
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -53,12 +53,12 @@ function New-AssetMaintenance() {
|
|||
[string]$title,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$startDate,
|
||||
[datetime]$startDate,
|
||||
|
||||
[parameter(mandatory = $false)]
|
||||
[string]$completionDate,
|
||||
[datetime]$completionDate,
|
||||
|
||||
[switch]$is_warranty = $false,
|
||||
[switch]$is_warranty=$false,
|
||||
|
||||
[decimal]$cost,
|
||||
|
||||
|
|
@ -76,11 +76,11 @@ function New-AssetMaintenance() {
|
|||
"supplier_id" = $supplier_id
|
||||
"asset_maintenance_type" = $asset_maintenance_type
|
||||
"title" = $title
|
||||
"start_date" = $startDate
|
||||
"is_warranty" = $is_warranty
|
||||
"start_date" = $startDate.ToString("yyyy-MM-dd")
|
||||
"is_warranty" = [Bool]::Parse($is_warranty)
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('completionDate')) { $Values.Add("completion_date", $completionDate) }
|
||||
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) }
|
||||
|
||||
|
|
|
|||
72
SnipeitPS/Public/New-CustomField.ps1
Normal file
72
SnipeitPS/Public/New-CustomField.ps1
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
Add a new Custom Field to Snipe-it asset system
|
||||
|
||||
.DESCRIPTION
|
||||
Add a new Custom Field to Snipe-it asset system
|
||||
|
||||
.PARAMETER Name
|
||||
Name of the Custom Field
|
||||
|
||||
.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-Field -Name "AntivirusInstalled" -Format "BOOLEAN" -HelpText "Is AntiVirus installed on Asset"
|
||||
#>
|
||||
|
||||
function New-CustomField()
|
||||
{
|
||||
[CmdletBinding(
|
||||
SupportsShouldProcess = $true,
|
||||
ConfirmImpact = "Low"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$Name,
|
||||
|
||||
[string]$HelpText,
|
||||
|
||||
[string]$Element = "text",
|
||||
|
||||
[string]$Format = "ANY",
|
||||
|
||||
[string]$CustomFormat,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$apiKey
|
||||
)
|
||||
|
||||
|
||||
$Values = @{
|
||||
"name" = $Name
|
||||
"help_text" = $HelpText
|
||||
"element" = $Element
|
||||
"format" = $Format
|
||||
"custom_format" = $CustomFormat
|
||||
}
|
||||
|
||||
#Convert Values to JSON format
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/fields"
|
||||
Method = 'post'
|
||||
Body = $Body
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
|
||||
{
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
|
|
@ -38,12 +38,16 @@ function New-Model()
|
|||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[string]$model_number,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$category_id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[int]$eol,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$fieldset_id,
|
||||
|
||||
|
|
@ -61,6 +65,9 @@ function New-Model()
|
|||
fieldset_id = $fieldset_id
|
||||
}
|
||||
|
||||
if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) }
|
||||
if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) }
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
|
|
|
|||
90
SnipeitPS/Public/Set-Model.ps1
Normal file
90
SnipeitPS/Public/Set-Model.ps1
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<#
|
||||
.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,
|
||||
ConfirmImpact = "Medium"
|
||||
)]
|
||||
|
||||
Param(
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$name,
|
||||
|
||||
[string]$model_number,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$category_id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$manufacturer_id,
|
||||
|
||||
[int]$eol,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[int]$fieldset_id,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[string]$url,
|
||||
|
||||
[parameter(mandatory = $true)]
|
||||
[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) }
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/models"
|
||||
Method = 'put'
|
||||
Body = $Body
|
||||
Token = $apiKey
|
||||
}
|
||||
|
||||
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
|
||||
$result = Invoke-SnipeitMethod @Parameters
|
||||
}
|
||||
|
||||
$result
|
||||
}
|
||||
Binary file not shown.
|
|
@ -1,10 +1,10 @@
|
|||
$scriptRoot = $PSScriptRoot + '\public'
|
||||
$scriptRoot = $PSScriptRoot + '\Public'
|
||||
|
||||
Get-ChildItem $scriptRoot *.ps1 | ForEach-Object {
|
||||
Import-Module $_.FullName
|
||||
}
|
||||
|
||||
$scriptRoot = $PSScriptRoot + '\private'
|
||||
$scriptRoot = $PSScriptRoot + '\Private'
|
||||
|
||||
Get-ChildItem $scriptRoot *.ps1 | ForEach-Object {
|
||||
Import-Module $_.FullName
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue