From 0acac3a29f582267486987461d832efec05e806e Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Thu, 29 Jul 2021 12:45:23 +0300 Subject: [PATCH 1/2] checkout asset when creating --- SnipeitPS/Public/New-SnipeitAsset.ps1 | 32 ++++++++++++++++++++-- SnipeitPS/Public/Set-SnipeitAssetOwner.ps1 | 3 ++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/SnipeitPS/Public/New-SnipeitAsset.ps1 b/SnipeitPS/Public/New-SnipeitAsset.ps1 index 89c6ca9..065ff51 100644 --- a/SnipeitPS/Public/New-SnipeitAsset.ps1 +++ b/SnipeitPS/Public/New-SnipeitAsset.ps1 @@ -45,6 +45,12 @@ Optional Default location id for the asset .PARAMETER image 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 URL of Snipeit system, can be set using Set-SnipeitInfo command @@ -72,12 +78,14 @@ function New-SnipeitAsset() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "Low" + ConfirmImpact = "Low", + DefaultParameterSetName = 'Create asset' )] Param( - [parameter(mandatory = $true)] + [parameter(ParameterSetName='Create asset',mandatory = $true)] + [parameter(ParameterSetName='Checkout asset when creating',mandatory = $true)] [int]$status_id, [parameter(mandatory = $true)] @@ -120,6 +128,13 @@ function New-SnipeitAsset() [ValidateScript({Test-Path $_})] [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)] [string]$url, @@ -143,6 +158,19 @@ function New-SnipeitAsset() $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 = @{ Uri = "$url/api/v1/hardware" Method = 'Post' diff --git a/SnipeitPS/Public/Set-SnipeitAssetOwner.ps1 b/SnipeitPS/Public/Set-SnipeitAssetOwner.ps1 index 0157c48..6db1de7 100644 --- a/SnipeitPS/Public/Set-SnipeitAssetOwner.ps1 +++ b/SnipeitPS/Public/Set-SnipeitAssetOwner.ps1 @@ -10,6 +10,9 @@ .PARAMETER assigned_id Id of target user , location or asset + .PARAMETER checkout_to_type + Checkout asset to one of following types user, location, asset + .PARAMETER note Notes about checkout From 52dfdb62f57ba21b6b9bb1cd97d4e7cb5bdb49fc Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Thu, 29 Jul 2021 12:49:16 +0300 Subject: [PATCH 2/2] update docs --- docs/New-SnipeitAsset.md | 84 ++++++++++++++++++++++++++--------- docs/Set-SnipeitAssetOwner.md | 2 +- 2 files changed, 63 insertions(+), 23 deletions(-) diff --git a/docs/New-SnipeitAsset.md b/docs/New-SnipeitAsset.md index 907ab69..47ef1fa 100644 --- a/docs/New-SnipeitAsset.md +++ b/docs/New-SnipeitAsset.md @@ -12,12 +12,22 @@ Add a new Asset to Snipe-it asset system ## SYNTAX +### Create asset (Default) ``` -New-SnipeitAsset [-status_id] [-model_id] [[-name] ] [[-asset_tag] ] - [[-serial] ] [[-company_id] ] [[-order_number] ] [[-notes] ] - [[-warranty_months] ] [[-purchase_cost] ] [[-purchase_date] ] - [[-supplier_id] ] [[-rtd_location_id] ] [[-image] ] [-url] [-apiKey] - [[-customfields] ] [-WhatIf] [-Confirm] [] +New-SnipeitAsset -status_id -model_id [-name ] [-asset_tag ] [-serial ] + [-company_id ] [-order_number ] [-notes ] [-warranty_months ] + [-purchase_cost ] [-purchase_date ] [-supplier_id ] [-rtd_location_id ] + [-image ] -url -apiKey [-customfields ] [-WhatIf] [-Confirm] + [] +``` + +### Checkout asset when creating +``` +New-SnipeitAsset -status_id -model_id [-name ] [-asset_tag ] [-serial ] + [-company_id ] [-order_number ] [-notes ] [-warranty_months ] + [-purchase_cost ] [-purchase_date ] [-supplier_id ] [-rtd_location_id ] + [-image ] -assigned_id -checkout_to_type -url -apiKey + [-customfields ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -54,7 +64,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 16 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -69,12 +79,42 @@ Parameter Sets: (All) Aliases: tag Required: False -Position: 4 +Position: Named Default value: None Accept pipeline input: 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 Optional Company id @@ -84,7 +124,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 6 +Position: Named Default value: 0 Accept pipeline input: False Accept wildcard characters: False @@ -100,7 +140,7 @@ Parameter Sets: (All) Aliases: CustomValues Required: False -Position: 17 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -115,7 +155,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 14 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -130,7 +170,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 2 +Position: Named Default value: 0 Accept pipeline input: False Accept wildcard characters: False @@ -145,7 +185,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 3 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -160,7 +200,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 8 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -175,7 +215,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 7 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -190,7 +230,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 10 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -205,7 +245,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 11 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -220,7 +260,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 13 +Position: Named Default value: 0 Accept pipeline input: False Accept wildcard characters: False @@ -235,7 +275,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 5 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -250,7 +290,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 1 +Position: Named Default value: 0 Accept pipeline input: False Accept wildcard characters: False @@ -265,7 +305,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 12 +Position: Named Default value: 0 Accept pipeline input: False Accept wildcard characters: False @@ -280,7 +320,7 @@ Parameter Sets: (All) Aliases: Required: True -Position: 15 +Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False @@ -295,7 +335,7 @@ Parameter Sets: (All) Aliases: Required: False -Position: 9 +Position: Named Default value: 0 Accept pipeline input: False Accept wildcard characters: False diff --git a/docs/Set-SnipeitAssetOwner.md b/docs/Set-SnipeitAssetOwner.md index 5af3c6a..1408e93 100644 --- a/docs/Set-SnipeitAssetOwner.md +++ b/docs/Set-SnipeitAssetOwner.md @@ -76,7 +76,7 @@ Accept wildcard characters: False ``` ### -checkout_to_type -{{ Fill checkout_to_type Description }} +Checkout asset to one of following types user, location, asset ```yaml Type: String