Merge pull request #136 from PetriAsi/feature/pipelineinput

Pipeline support for Set functions
This commit is contained in:
Petri Asikainen 2021-06-06 07:58:49 +03:00 committed by GitHub
commit d4c138604d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 259 additions and 195 deletions

View file

@ -79,10 +79,10 @@ function Get-SnipeItAsset() {
[int]$id,
[string]$asset_tag,
[Alias('asset_serial')]
[string]$serial,
[string]$asset_serial,
[int]$order_number,
[string]$order_number,
[int]$model_id,

View file

@ -44,7 +44,7 @@ function Get-SnipeItLicense() {
[string]$product_key,
[int]$order_number,
[string]$order_number,
[string]$purchase_order,

View file

@ -8,6 +8,9 @@ Creates new accessory on Snipe-It system
.PARAMETER name
Accessory name
.PARAMETER notes
Notes about the accessory
.PARAMETER qty
Quantity of the accessory you have

View file

@ -6,7 +6,10 @@ Updates accessory on Snipe-It system
Updates accessory on Snipe-It system
.PARAMETER name
ID number of Accessory on Snipe-It system
ID number of Accessory or array of IDs on Snipe-It system
.PARAMETER notes
Notes about the accessory
.PARAMETER qty
Quantity of the accessory you have
@ -64,8 +67,8 @@ function Set-SnipeItAccessory() {
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[ValidateLength(3, 255)]
[string]$name,
@ -81,6 +84,7 @@ function Set-SnipeItAccessory() {
[ValidateRange(1, [int]::MaxValue)]
[int]$manufacturer_id,
[AllowEmptyString]
[string]$order_number,
[float]$purchase_cost,
@ -99,27 +103,33 @@ function Set-SnipeItAccessory() {
[string]$apiKey
)
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
begin {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
$Body = $Values | ConvertTo-Json;
}
process {
foreach($accessory_id in $id){
$Parameters = @{
Uri = "$url/api/v1/accessories/$accessory_id"
Method = 'Patch'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
$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

@ -5,7 +5,7 @@
Checkout accessory to user
.PARAMETER id
Unique ID For accessory to checkout
Unique ID For accessory or array of IDs to checkout
.PARAMETER assigned_id
Id of target user
@ -30,8 +30,8 @@ function Set-SnipeItAccessoryOwner()
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[parameter(mandatory = $true)]
[int]$assigned_to,
@ -44,22 +44,27 @@ function Set-SnipeItAccessoryOwner()
[parameter(mandatory = $true)]
[string]$apiKey
)
begin{
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/accessories/$id/checkout"
Method = 'POST'
Body = $Body
Token = $apiKey
$Body = $Values | ConvertTo-Json;
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
process {
foreach($accessory_id in $id){
$Parameters = @{
Uri = "$url/api/v1/accessories/$accessory_id/checkout"
Method = 'POST'
Body = $Body
Token = $apiKey
}
return $result
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
return $result
}
}
}

View file

@ -6,7 +6,7 @@
Long description
.PARAMETER id
ID of the Asset
ID of the Asset or array of IDs
.PARAMETER Name
Asset name
@ -70,6 +70,9 @@
.EXAMPLE
Set-SnipeItAsset -id 1 -status_id 1 -model_id 1 -name "Machine1" -CustomValues = @{ "_snipeit_os_5 = "Windows 10 Pro" }
.EXAMPLE
Get-SnipeItAsset -serial 12345678 | Set-SnipeItAsset -notes 'Just updated'
#>
function Set-SnipeItAsset()
@ -80,8 +83,8 @@ function Set-SnipeItAsset()
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[string]$name,
@ -124,33 +127,38 @@ function Set-SnipeItAsset()
[hashtable] $customfields
)
begin{
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
}
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
if ($customfields)
{
$Values += $customfields
}
$Body = $Values | ConvertTo-Json;
}
if ($customfields)
{
$Values += $customfields
process {
foreach($asset_id in $id){
$Parameters = @{
Uri = "$url/api/v1/hardware/$asset_id"
Method = $RequestType
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/hardware/$id"
Method = $RequestType
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

View file

@ -5,7 +5,7 @@
Checkout asset to user/localtion/asset
.PARAMETER ID
Unique ID For asset to checkout
Unique IDs For assets to checkout
.PARAMETER assigned_id
Id of target user , location or asset
@ -41,8 +41,8 @@ function Set-SnipeItAssetOwner()
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[parameter(mandatory = $true)]
[int]$assigned_id,
@ -65,41 +65,48 @@ function Set-SnipeItAssetOwner()
[string]$apiKey
)
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
begin{
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($Values['expected_checkin']) {
$Values['expected_checkin'] = $values['expected_checkin'].ToString("yyyy-MM-dd")
}
if ($Values['checkout_at']) {
$Values['checkout_at'] = $values['checkout_at'].ToString("yyyy-MM-dd")
}
switch ($checkout_to_type)
{
'location' { $Values += @{ "assigned_location" = $assigned_id } }
'user' { $Values += @{ "assigned_user" = $assigned_id } }
'asset' { $Values += @{ "assigned_asset" = $assigned_id } }
}
#This can be removed now
if($Values.ContainsKey('assigned_id')){$Values.Remove('assigned_id')}
$Body = $Values | ConvertTo-Json;
if ($Values['expected_checkin']) {
$Values['expected_checkin'] = $values['expected_checkin'].ToString("yyyy-MM-dd")
}
if ($Values['checkout_at']) {
$Values['checkout_at'] = $values['checkout_at'].ToString("yyyy-MM-dd")
process{
foreach($asset_id in $id){
$Parameters = @{
Uri = "$url/api/v1/hardware/$asset_id/checkout"
Method = 'POST'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
return $result
}
}
switch ($checkout_to_type)
{
'location' { $Values += @{ "assigned_location" = $assigned_id } }
'user' { $Values += @{ "assigned_user" = $assigned_id } }
'asset' { $Values += @{ "assigned_asset" = $assigned_id } }
}
#This can be removed now
if($Values.ContainsKey('assigned_id')){$Values.Remove('assigned_id')}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/hardware/$id/checkout"
Method = 'POST'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
return $result
}

View file

@ -6,7 +6,7 @@
Updates licence on Snipe-It system
.PARAMETER id
ID number of licence
ID number of license or array of license IDs
.PARAMETER name
Name of license
@ -77,8 +77,8 @@ function Set-SnipeItLicense() {
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true, ValueFromPipelineByPropertyName)]
[int[]]$id,
[ValidateLength(3, 255)]
[string]$name,
@ -128,36 +128,39 @@ function Set-SnipeItLicense() {
[parameter(mandatory = $true)]
[string]$apiKey
)
begin{
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['expiration_date']) {
$values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd")
}
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;
}
process {
foreach($license_id in $id){
$Parameters = @{
Uri = "$url/api/v1/licenses/$license_id"
Method = 'PUT'
Body = $Body
Token = $apiKey
}
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
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

@ -5,7 +5,7 @@
Checkout specific license seat to user, asset or both
.PARAMETER ID
Unique ID For asset to checkout
Unique ID For license to checkout or array of IDs
.PARAMETER assigned_to
Id of target user
@ -40,7 +40,7 @@ function Set-SnipeItLicenseSeat()
Param(
[parameter(mandatory = $true)]
[int]$id,
[int[]]$id,
[parameter(mandatory = $true)]
[int]$seat_id,
@ -58,21 +58,27 @@ function Set-SnipeItLicenseSeat()
[string]$apiKey
)
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
begin{
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/licenses/$id/seats/$seat_id"
Method = 'Patch'
Body = $Body
Token = $apiKey
$Body = $Values | ConvertTo-Json;
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
process{
foreach($license_id in $id) {
$Parameters = @{
Uri = "$url/api/v1/licenses/$license_id/seats/$seat_id"
Method = 'Patch'
Body = $Body
Token = $apiKey
}
return $result
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
return $result
}
}
}

View file

@ -5,6 +5,9 @@
.DESCRIPTION
Long description
.PARAMETER id
ID number of location or array or IDs
.PARAMETER name
Name of Location
@ -59,8 +62,8 @@ function Set-SnipeitLocation() {
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[ValidateLength(3, 255)]
[string]$name,
@ -92,23 +95,29 @@ function Set-SnipeitLocation() {
[string]$apiKey
)
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
begin{
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/locations/$id"
Method = 'PUT'
Body = $Body
Token = $apiKey
$Body = $Values | ConvertTo-Json;
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
process{
foreach ($location_id in $id) {
$Parameters = @{
Uri = "$url/api/v1/locations/$location_id"
Method = 'PUT'
Body = $Body
Token = $apiKey
}
$result
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
}

View file

@ -6,7 +6,7 @@
Updates Model on Snipe-it asset system
.PARAMETER id
ID number of the Asset Model
ID number of the Asset Model or array of IDs
.PARAMETER name
Name of the Asset Model
@ -40,8 +40,8 @@ function Set-SnipeItModel() {
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[ValidateLength(1, 255)]
[string]$name,
@ -66,22 +66,27 @@ function Set-SnipeItModel() {
[string]$apiKey
)
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
begin {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/models/$id"
Method = 'put'
Body = $Body
Token = $apiKey
$Body = $Values | ConvertTo-Json;
}
process {
foreach ($model_id in $id) {
$Parameters = @{
Uri = "$url/api/v1/models/$model_id"
Method = 'put'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
$result
}

View file

@ -2,6 +2,9 @@
.SYNOPSIS
Creates a new user
.PARAMETER id
ID number of Snipe--It user or array of IDs
.DESCRIPTION
Creates a new user to Snipe-IT system
@ -68,8 +71,8 @@ function Set-SnipeItUser() {
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true,ValueFromPipelineByPropertyName)]
[int[]]$id,
[string]$first_name,
@ -103,23 +106,28 @@ function Set-SnipeItUser() {
[parameter(mandatory = $true)]
[string]$apiKey
)
begin{
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/users/$id"
Method = 'PATCH'
Body = $Body
Token = $apiKey
$Body = $Values | ConvertTo-Json;
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
process{
foreach($user_id in $id) {
$Parameters = @{
Uri = "$url/api/v1/users/$user_id"
Method = 'PATCH'
Body = $Body
Token = $apiKey
}
$result
If ($PSCmdlet.ShouldProcess("ShouldProcess?")) {
$result = Invoke-SnipeitMethod @Parameters
}
$result
}
}
}