Merge pull request #204 from PetriAsi/feature/checkout-on-creation

Feature/checkout asset when creating
This commit is contained in:
Petri Asikainen 2021-07-29 12:59:02 +03:00 committed by GitHub
commit cde16b1983
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 96 additions and 25 deletions

View file

@ -45,6 +45,12 @@ Optional Default location id for the asset
.PARAMETER image .PARAMETER image
Asset image filename and path Asset image filename and path
.PARAMETER assigned_id
Id of target user , location or asset
.PARAMETER checkout_to_type
Checkout asset when creating to one of following types user, location or asset.
.PARAMETER url .PARAMETER url
URL of Snipeit system, can be set using Set-SnipeitInfo command URL of Snipeit system, can be set using Set-SnipeitInfo command
@ -72,12 +78,14 @@ function New-SnipeitAsset()
{ {
[CmdletBinding( [CmdletBinding(
SupportsShouldProcess = $true, SupportsShouldProcess = $true,
ConfirmImpact = "Low" ConfirmImpact = "Low",
DefaultParameterSetName = 'Create asset'
)] )]
Param( Param(
[parameter(mandatory = $true)] [parameter(ParameterSetName='Create asset',mandatory = $true)]
[parameter(ParameterSetName='Checkout asset when creating',mandatory = $true)]
[int]$status_id, [int]$status_id,
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
@ -120,6 +128,13 @@ function New-SnipeitAsset()
[ValidateScript({Test-Path $_})] [ValidateScript({Test-Path $_})]
[string]$image, [string]$image,
[parameter(ParameterSetName='Checkout asset when creating',mandatory = $true)]
[int]$assigned_id,
[parameter(ParameterSetName='Checkout asset when creating',mandatory = $true)]
[ValidateSet("location","asset","user")]
[string] $checkout_to_type = "user",
[parameter(mandatory = $true)] [parameter(mandatory = $true)]
[string]$url, [string]$url,
@ -143,6 +158,19 @@ function New-SnipeitAsset()
$Values += $customfields $Values += $customfields
} }
#Checkout asset when creating it
if ($PsCmdlet.ParameterSetName -eq 'Checkout asset when creating'){
switch ($checkout_to_type){
'location' { $Values += @{ "assigned_location" = $assigned_id } }
'user' { $Values += @{ "assigned_user" = $assigned_id } }
'asset' { $Values += @{ "assigned_asset" = $assigned_id } }
}
#This are not needed for API
if($Values.ContainsKey('assigned_id')){$Values.Remove('assigned_id')}
if($Values.ContainsKey('checkout_to_type')){$Values.Remove('checkout_to_type')}
}
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/hardware" Uri = "$url/api/v1/hardware"
Method = 'Post' Method = 'Post'

View file

@ -10,6 +10,9 @@
.PARAMETER assigned_id .PARAMETER assigned_id
Id of target user , location or asset Id of target user , location or asset
.PARAMETER checkout_to_type
Checkout asset to one of following types user, location, asset
.PARAMETER note .PARAMETER note
Notes about checkout Notes about checkout

View file

@ -12,12 +12,22 @@ Add a new Asset to Snipe-it asset system
## SYNTAX ## SYNTAX
### Create asset (Default)
``` ```
New-SnipeitAsset [-status_id] <Int32> [-model_id] <Int32> [[-name] <String>] [[-asset_tag] <String>] New-SnipeitAsset -status_id <Int32> -model_id <Int32> [-name <String>] [-asset_tag <String>] [-serial <String>]
[[-serial] <String>] [[-company_id] <Int32>] [[-order_number] <String>] [[-notes] <String>] [-company_id <Int32>] [-order_number <String>] [-notes <String>] [-warranty_months <Int32>]
[[-warranty_months] <Int32>] [[-purchase_cost] <String>] [[-purchase_date] <DateTime>] [-purchase_cost <String>] [-purchase_date <DateTime>] [-supplier_id <Int32>] [-rtd_location_id <Int32>]
[[-supplier_id] <Int32>] [[-rtd_location_id] <Int32>] [[-image] <String>] [-url] <String> [-apiKey] <String> [-image <String>] -url <String> -apiKey <String> [-customfields <Hashtable>] [-WhatIf] [-Confirm]
[[-customfields] <Hashtable>] [-WhatIf] [-Confirm] [<CommonParameters>] [<CommonParameters>]
```
### Checkout asset when creating
```
New-SnipeitAsset -status_id <Int32> -model_id <Int32> [-name <String>] [-asset_tag <String>] [-serial <String>]
[-company_id <Int32>] [-order_number <String>] [-notes <String>] [-warranty_months <Int32>]
[-purchase_cost <String>] [-purchase_date <DateTime>] [-supplier_id <Int32>] [-rtd_location_id <Int32>]
[-image <String>] -assigned_id <Int32> -checkout_to_type <String> -url <String> -apiKey <String>
[-customfields <Hashtable>] [-WhatIf] [-Confirm] [<CommonParameters>]
``` ```
## DESCRIPTION ## DESCRIPTION
@ -54,7 +64,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: True Required: True
Position: 16 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -69,12 +79,42 @@ Parameter Sets: (All)
Aliases: tag Aliases: tag
Required: False Required: False
Position: 4 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
``` ```
### -assigned_id
Id of target user , location or asset
```yaml
Type: Int32
Parameter Sets: Checkout asset when creating
Aliases:
Required: True
Position: Named
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False
```
### -checkout_to_type
Checkout asset when creating to one of following types user, location or asset.
```yaml
Type: String
Parameter Sets: Checkout asset when creating
Aliases:
Required: True
Position: Named
Default value: User
Accept pipeline input: False
Accept wildcard characters: False
```
### -company_id ### -company_id
Optional Company id Optional Company id
@ -84,7 +124,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 6 Position: Named
Default value: 0 Default value: 0
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -100,7 +140,7 @@ Parameter Sets: (All)
Aliases: CustomValues Aliases: CustomValues
Required: False Required: False
Position: 17 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -115,7 +155,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 14 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -130,7 +170,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: True Required: True
Position: 2 Position: Named
Default value: 0 Default value: 0
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -145,7 +185,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 3 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -160,7 +200,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 8 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -175,7 +215,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 7 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -190,7 +230,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 10 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -205,7 +245,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 11 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -220,7 +260,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 13 Position: Named
Default value: 0 Default value: 0
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -235,7 +275,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 5 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -250,7 +290,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: True Required: True
Position: 1 Position: Named
Default value: 0 Default value: 0
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -265,7 +305,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 12 Position: Named
Default value: 0 Default value: 0
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -280,7 +320,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: True Required: True
Position: 15 Position: Named
Default value: None Default value: None
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False
@ -295,7 +335,7 @@ Parameter Sets: (All)
Aliases: Aliases:
Required: False Required: False
Position: 9 Position: Named
Default value: 0 Default value: 0
Accept pipeline input: False Accept pipeline input: False
Accept wildcard characters: False Accept wildcard characters: False

View file

@ -76,7 +76,7 @@ Accept wildcard characters: False
``` ```
### -checkout_to_type ### -checkout_to_type
{{ Fill checkout_to_type Description }} Checkout asset to one of following types user, location, asset
```yaml ```yaml
Type: String Type: String