From 923838e15f8f4b0b17905155e4996c05de48aef9 Mon Sep 17 00:00:00 2001 From: Petri Asikainen Date: Mon, 23 Aug 2021 18:01:09 +0300 Subject: [PATCH] begin, process, end --- SnipeitPS/Private/Invoke-SnipeitMethod.ps1 | 10 +- .../Private/Reset-SnipeitPSLegacyApi.ps1 | 1 + SnipeitPS/Private/Set-SnipeitPSLegacyUrl.ps1 | 2 +- SnipeitPS/Public/Connect-SnipeitPS.ps1 | 2 +- SnipeitPS/Public/Get-SnipeitAccessory.ps1 | 96 ++++++++-------- .../Public/Get-SnipeitAccessoryOwner.ps1 | 47 ++++---- SnipeitPS/Public/Get-SnipeitActivity.ps1 | 105 ++++++++--------- SnipeitPS/Public/Get-SnipeitAsset.ps1 | 106 +++++++++--------- .../Public/Get-SnipeitAssetMaintenance.ps1 | 83 +++++++------- SnipeitPS/Public/Get-SnipeitCategory.ps1 | 98 ++++++++-------- SnipeitPS/Public/Get-SnipeitCompany.ps1 | 99 ++++++++-------- SnipeitPS/Public/Get-SnipeitComponent.ps1 | 100 +++++++++-------- SnipeitPS/Public/Get-SnipeitCustomField.ps1 | 57 +++++----- SnipeitPS/Public/Get-SnipeitDepartment.ps1 | 99 ++++++++-------- SnipeitPS/Public/Get-SnipeitFieldset.ps1 | 55 ++++----- SnipeitPS/Public/Get-SnipeitLicense.ps1 | 97 ++++++++-------- SnipeitPS/Public/Get-SnipeitLicenseSeat.ps1 | 93 +++++++-------- SnipeitPS/Public/Get-SnipeitLocation.ps1 | 101 +++++++++-------- SnipeitPS/Public/Get-SnipeitManufacturer.ps1 | 101 +++++++++-------- SnipeitPS/Public/Get-SnipeitModel.ps1 | 100 +++++++++-------- SnipeitPS/Public/Get-SnipeitStatus.ps1 | 101 +++++++++-------- SnipeitPS/Public/Get-SnipeitSupplier.ps1 | 99 ++++++++-------- SnipeitPS/Public/Get-SnipeitUser.ps1 | 93 +++++++-------- SnipeitPS/Public/New-SnipeitAccessory.ps1 | 58 +++++----- SnipeitPS/Public/New-SnipeitAsset.ps1 | 90 ++++++++------- .../Public/New-SnipeitAssetMaintenance.ps1 | 69 ++++++------ SnipeitPS/Public/New-SnipeitAudit.ps1 | 65 ++++++----- SnipeitPS/Public/New-SnipeitCompany.ps1 | 51 +++++---- SnipeitPS/Public/New-SnipeitComponent.ps1 | 59 +++++----- SnipeitPS/Public/New-SnipeitConsumable.ps1 | 4 +- SnipeitPS/Public/New-SnipeitDepartment.ps1 | 51 +++++---- SnipeitPS/Public/New-SnipeitLicense.ps1 | 76 +++++++------ SnipeitPS/Public/New-SnipeitLocation.ps1 | 52 +++++---- SnipeitPS/Public/New-SnipeitManufacturer.ps1 | 58 +++++----- SnipeitPS/Public/New-SnipeitModel.ps1 | 70 ++++++------ SnipeitPS/Public/New-SnipeitSupplier.ps1 | 51 +++++---- SnipeitPS/Public/New-SnipeitUser.ps1 | 59 +++++----- 37 files changed, 1357 insertions(+), 1201 deletions(-) diff --git a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 index 997bb41..658f593 100644 --- a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 +++ b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 @@ -36,18 +36,17 @@ function Invoke-SnipeitMethod { BEGIN { #use legacy per command based url and apikey if ( $null -ne $SnipeitPSSession.legacyUrl -and $null -ne $SnipeitPSSession.legacyApiKey ) { - [string]$Url = $SnipeitPSSession.legacyrl + [string]$Url = $SnipeitPSSession.legacyUrl Write-Debug "Invoke-SnipeitMethod url: $Url" $Token = ConvertFrom-SecureString -AsPlainText -SecureString $SnipeitPSSession.legacyApiKey - throw "Cannot connect to Snipe it. Please run Connect-SnipePS to set connection information." } elseif ($null -ne $SnipeitPSSession.url -and $null -ne $SnipeitPSSession.apiKey) { - - } else { [string]$Url = $SnipeitPSSession.url Write-Debug "Invoke-SnipeitMethod url: $Url" $Token = ConvertFrom-SecureString -AsPlainText -SecureString $SnipeitPSSession.apiKey + } else { + throw "Please use Connect-SnipeitPS to setup connection before any other commands." } # Validation of parameters @@ -57,9 +56,6 @@ function Invoke-SnipeitMethod { Throw $exception } - # Double check those old deprecated -url parameters - $Url = $Url.TrimEnd('/') - #Build request uri $apiUri = "$Url$Api" #To support images "image" property have be handled before this diff --git a/SnipeitPS/Private/Reset-SnipeitPSLegacyApi.ps1 b/SnipeitPS/Private/Reset-SnipeitPSLegacyApi.ps1 index 5449d3b..c4508c3 100644 --- a/SnipeitPS/Private/Reset-SnipeitPSLegacyApi.ps1 +++ b/SnipeitPS/Private/Reset-SnipeitPSLegacyApi.ps1 @@ -6,6 +6,7 @@ function Reset-SnipeitPSLegacyApi { param( ) process { + Write-Verbose 'Reset-SnipeitPSLegacyApi' if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $SnipeitPSSession.legacyUrl = $null $SnipeitPSSession.legacyApiKey = $null diff --git a/SnipeitPS/Private/Set-SnipeitPSLegacyUrl.ps1 b/SnipeitPS/Private/Set-SnipeitPSLegacyUrl.ps1 index 2cd1c63..0b08778 100644 --- a/SnipeitPS/Private/Set-SnipeitPSLegacyUrl.ps1 +++ b/SnipeitPS/Private/Set-SnipeitPSLegacyUrl.ps1 @@ -8,7 +8,7 @@ function Set-SnipeitPSLegacyUrl { ) process { if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $SnipeitPSSession.legacyUrl = $url + $SnipeitPSSession.legacyUrl = $url.TrimEnd('/') } } } diff --git a/SnipeitPS/Public/Connect-SnipeitPS.ps1 b/SnipeitPS/Public/Connect-SnipeitPS.ps1 index bb44411..f305827 100644 --- a/SnipeitPS/Public/Connect-SnipeitPS.ps1 +++ b/SnipeitPS/Public/Connect-SnipeitPS.ps1 @@ -69,7 +69,7 @@ function Connect-SnipeitPS { switch ($PsCmdlet.ParameterSetName) { 'Connect with url and apikey' { $SnipeitPSSession.url = $url.TrimEnd('/') - $SnipeitPSSession.apiKey = $apiKey | ConvertTo-SecureString -AsPlainText + $SnipeitPSSession.apiKey = ConvertTo-SecureString -AsPlainText -String $apiKey } 'Connect with url and secure apikey' { diff --git a/SnipeitPS/Public/Get-SnipeitAccessory.ps1 b/SnipeitPS/Public/Get-SnipeitAccessory.ps1 index af9222b..0e0aff8 100644 --- a/SnipeitPS/Public/Get-SnipeitAccessory.ps1 +++ b/SnipeitPS/Public/Get-SnipeitAccessory.ps1 @@ -85,55 +85,61 @@ function Get-SnipeitAccessory() { [parameter(mandatory = $false)] [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - switch($PsCmdlet.ParameterSetName) { - 'Search' {$api = "/api/v1/accessories"} - 'Get by ID' {$api= "/api/v1/accessories/$id"} - 'Accessories checked out to user id' {$api = "/api/v1/users/$user_id/accessories"} - } - - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitAccessory @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + switch($PsCmdlet.ParameterSetName) { + 'Search' {$api = "/api/v1/accessories"} + 'Get by ID' {$api= "/api/v1/accessories/$id"} + 'Accessories checked out to user id' {$api = "/api/v1/users/$user_id/accessories"} + } + + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitAccessory @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitAccessoryOwner.ps1 b/SnipeitPS/Public/Get-SnipeitAccessoryOwner.ps1 index 3cc6174..70965d8 100644 --- a/SnipeitPS/Public/Get-SnipeitAccessoryOwner.ps1 +++ b/SnipeitPS/Public/Get-SnipeitAccessoryOwner.ps1 @@ -32,30 +32,33 @@ function Get-SnipeitAccessoryOwner() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + $Parameters = @{ + Api = "/api/v1/accessories/$id/checkedout" + Method = 'GET' + } - $Parameters = @{ - Api = "/api/v1/accessories/$id/checkedout" - Method = 'GET' + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } + } + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + $result } - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi - } - - return $result } diff --git a/SnipeitPS/Public/Get-SnipeitActivity.ps1 b/SnipeitPS/Public/Get-SnipeitActivity.ps1 index b8b6541..133779c 100644 --- a/SnipeitPS/Public/Get-SnipeitActivity.ps1 +++ b/SnipeitPS/Public/Get-SnipeitActivity.ps1 @@ -77,59 +77,64 @@ function Get-SnipeitActivity() { [parameter(mandatory = $false)] [string]$apiKey ) - - if (($target_type -and -not $target_id) -or - ($target_id -and -not $target_type)) { - throw "Please specify both target_type and target_id" - } - - if (($item_type -and -not $item_id) -or - ($item_id -and -not $item_type)) { - throw "Please specify both item_type and item_id" - } - - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - - - $Parameters = @{ - Api = "/api/v1/reports/activity" - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitActivity @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + begin { + if (($target_type -and -not $target_id) -or + ($target_id -and -not $target_type)) { + throw "Please specify both target_type and target_id" + } + + if (($item_type -and -not $item_id) -or + ($item_id -and -not $item_type)) { + throw "Please specify both item_type and item_id" + } + + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + + + $Parameters = @{ + Api = "/api/v1/reports/activity" + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitActivity @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitAsset.ps1 b/SnipeitPS/Public/Get-SnipeitAsset.ps1 index c87ca1a..d1bd734 100644 --- a/SnipeitPS/Public/Get-SnipeitAsset.ps1 +++ b/SnipeitPS/Public/Get-SnipeitAsset.ps1 @@ -206,61 +206,67 @@ function Get-SnipeitAsset() { [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - switch ($PsCmdlet.ParameterSetName) { - 'Search' { $api = "/api/v1/hardware" } - 'Get with id' {$api= "/api/v1/hardware/$id"} - 'Get with asset tag' {$api= "/api/v1/hardware/bytag/$asset_tag"} - 'Get with serial' { $api= "/api/v1/hardware/byserial/$serial"} - 'Assets due auditing soon' {$api = "/api/v1/hardware/audit/due"} - 'Assets overdue for auditing' {$api = "/api/v1/hardware/audit/overdue"} - 'Assets checked out to user id'{$api = "/api/v1/users/$user_id/assets"} - 'Assets with component id' {$api = "/api/v1/components/$component_id/assets"} - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - Write-Verbose "Callargs: $($callargs | convertto-json)" - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitAsset @callargs - $res - if ( $res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + switch ($PsCmdlet.ParameterSetName) { + 'Search' { $api = "/api/v1/hardware" } + 'Get with id' {$api= "/api/v1/hardware/$id"} + 'Get with asset tag' {$api= "/api/v1/hardware/bytag/$asset_tag"} + 'Get with serial' { $api= "/api/v1/hardware/byserial/$serial"} + 'Assets due auditing soon' {$api = "/api/v1/hardware/audit/due"} + 'Assets overdue for auditing' {$api = "/api/v1/hardware/audit/overdue"} + 'Assets checked out to user id'{$api = "/api/v1/users/$user_id/assets"} + 'Assets with component id' {$api = "/api/v1/components/$component_id/assets"} + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + Write-Verbose "Callargs: $($callargs | convertto-json)" + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitAsset @callargs + $res + if ( $res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitAssetMaintenance.ps1 b/SnipeitPS/Public/Get-SnipeitAssetMaintenance.ps1 index 3d14a10..e07dcc9 100644 --- a/SnipeitPS/Public/Get-SnipeitAssetMaintenance.ps1 +++ b/SnipeitPS/Public/Get-SnipeitAssetMaintenance.ps1 @@ -60,50 +60,55 @@ function Get-SnipeitAssetMaintenance() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - - $Parameters = @{ - Api = "/api/v1/maintenances" - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitAssetMaintenance @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + $Parameters = @{ + Api = "/api/v1/maintenances" + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitAssetMaintenance @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitCategory.ps1 b/SnipeitPS/Public/Get-SnipeitCategory.ps1 index f8a1bed..1c41d4b 100644 --- a/SnipeitPS/Public/Get-SnipeitCategory.ps1 +++ b/SnipeitPS/Public/Get-SnipeitCategory.ps1 @@ -59,58 +59,64 @@ function Get-SnipeitCategory() { [parameter(mandatory = $false)] [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $api = "/api/v1/categories" + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - if ($search -and $id ) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " - } + $api = "/api/v1/categories" - if ($id) { - $api= "/api/v1/categories/$id" - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitCategory @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $api= "/api/v1/categories/$id" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } + } + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitCategory @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitCompany.ps1 b/SnipeitPS/Public/Get-SnipeitCompany.ps1 index 3db123e..98237ac 100644 --- a/SnipeitPS/Public/Get-SnipeitCompany.ps1 +++ b/SnipeitPS/Public/Get-SnipeitCompany.ps1 @@ -61,58 +61,63 @@ function Get-SnipeitCompany() { [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $api = "/api/v1/companies" + $api = "/api/v1/companies" - if ($search -and $id ) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " - } - - if ($id) { - $api= "/api/v1/companies/$id" - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitCompany @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $api= "/api/v1/companies/$id" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } + } + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitCompany @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitComponent.ps1 b/SnipeitPS/Public/Get-SnipeitComponent.ps1 index 663b8be..4c6913c 100644 --- a/SnipeitPS/Public/Get-SnipeitComponent.ps1 +++ b/SnipeitPS/Public/Get-SnipeitComponent.ps1 @@ -78,58 +78,64 @@ function Get-SnipeitComponent() { [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $api = "/api/v1/components" + $api = "/api/v1/components" - if ($search -and $id ) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " - } - - if ($id) { - $api= "/api/v1/components/$id" - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitComponent @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $api= "/api/v1/components/$id" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitComponent @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitCustomField.ps1 b/SnipeitPS/Public/Get-SnipeitCustomField.ps1 index 08a8ec2..f83429c 100644 --- a/SnipeitPS/Public/Get-SnipeitCustomField.ps1 +++ b/SnipeitPS/Public/Get-SnipeitCustomField.ps1 @@ -33,37 +33,40 @@ function Get-SnipeitCustomField() { [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - if ($id) { - $api= "/api/v1/fields/$id" - } else { - $api = "/api/v1/fields" + if ($id) { + $api= "/api/v1/fields/$id" + } else { + $api = "/api/v1/fields" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - $Parameters = @{ - Api = $api - Method = 'Get' - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey + process { + $result = Invoke-SnipeitMethod @Parameters + $result } - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - - - $result = Invoke-SnipeitMethod @Parameters - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitDepartment.ps1 b/SnipeitPS/Public/Get-SnipeitDepartment.ps1 index 2812f6b..ed0ab81 100644 --- a/SnipeitPS/Public/Get-SnipeitDepartment.ps1 +++ b/SnipeitPS/Public/Get-SnipeitDepartment.ps1 @@ -66,60 +66,65 @@ function Get-SnipeitDepartment() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $api = "/api/v1/departments" + $api = "/api/v1/departments" - if ($search -and $id ) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " - } - - if ($id) { - $api= "/api/v1/departments/$id" - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitDepartment @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $api= "/api/v1/departments/$id" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } + } + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitDepartment @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitFieldset.ps1 b/SnipeitPS/Public/Get-SnipeitFieldset.ps1 index fd54228..37790c0 100644 --- a/SnipeitPS/Public/Get-SnipeitFieldset.ps1 +++ b/SnipeitPS/Public/Get-SnipeitFieldset.ps1 @@ -31,36 +31,39 @@ function Get-SnipeitFieldset() { [parameter(mandatory = $false)] [string]$apiKey ) + bagin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + if ($id) { + $api = "/api/v1/fieldsets/$id" + } else { + $api = "/api/v1/fieldsets" + } - if ($id) { - $api = "/api/v1/fieldsets/$id" - } else { - $api = "/api/v1/fieldsets" + $Parameters = @{ + Api = $api + Method = 'Get' + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } + process { + $result = Invoke-SnipeitMethod @Parameters - $Parameters = @{ - Api = $api - Method = 'Get' + $result } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - $result = Invoke-SnipeitMethod @Parameters - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitLicense.ps1 b/SnipeitPS/Public/Get-SnipeitLicense.ps1 index 4a15492..f739610 100644 --- a/SnipeitPS/Public/Get-SnipeitLicense.ps1 +++ b/SnipeitPS/Public/Get-SnipeitLicense.ps1 @@ -104,57 +104,62 @@ function Get-SnipeitLicense() { [parameter(mandatory = $false)] [string]$apiKey ) + bagin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - - switch($PsCmdlet.ParameterSetName) { - 'Search' {$api = "/api/v1/licenses"} - 'Get with ID' {$api= "/api/v1/licenses/$id"} - 'Get licenses checked out to user ID' {$api= "/api/v1/users/$user_id/licenses"} - 'Get licenses checked out to asset ID' {$api= "/api/v1/hardware/$asset_id/licenses"} - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitLicense @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + switch($PsCmdlet.ParameterSetName) { + 'Search' {$api = "/api/v1/licenses"} + 'Get with ID' {$api= "/api/v1/licenses/$id"} + 'Get licenses checked out to user ID' {$api= "/api/v1/users/$user_id/licenses"} + 'Get licenses checked out to asset ID' {$api= "/api/v1/hardware/$asset_id/licenses"} + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitLicense @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitLicenseSeat.ps1 b/SnipeitPS/Public/Get-SnipeitLicenseSeat.ps1 index 3b4ccce..67ad9d2 100644 --- a/SnipeitPS/Public/Get-SnipeitLicenseSeat.ps1 +++ b/SnipeitPS/Public/Get-SnipeitLicenseSeat.ps1 @@ -53,57 +53,62 @@ function Get-SnipeitLicenseSeat() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - - $api = "/api/v1/licenses/$id/seats" + $api = "/api/v1/licenses/$id/seats" - if ($seat_id) { - $api= "/api/v1/licenses/$id/seats/$seat_id" - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitLicenseSeat @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + if ($seat_id) { + $api= "/api/v1/licenses/$id/seats/$seat_id" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitLicenseSeat @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitLocation.ps1 b/SnipeitPS/Public/Get-SnipeitLocation.ps1 index 2a59231..1fa5c13 100644 --- a/SnipeitPS/Public/Get-SnipeitLocation.ps1 +++ b/SnipeitPS/Public/Get-SnipeitLocation.ps1 @@ -59,60 +59,65 @@ function Get-SnipeitLocation() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $api = "/api/v1/locations" - $api = "/api/v1/locations" - - if ($search -and $id ) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " - } - - if ($id) { - $api= "/api/v1/locations/$id" - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitLocation @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $api= "/api/v1/locations/$id" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitLocation @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitManufacturer.ps1 b/SnipeitPS/Public/Get-SnipeitManufacturer.ps1 index af178f9..6512040 100644 --- a/SnipeitPS/Public/Get-SnipeitManufacturer.ps1 +++ b/SnipeitPS/Public/Get-SnipeitManufacturer.ps1 @@ -60,59 +60,64 @@ function Get-SnipeitManufacturer() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $api = "/api/v1/manufacturers" - $api = "/api/v1/manufacturers" - - if ($search -and $id ) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " - } - - if ($id) { - $api= "/api/v1/manufacturers/$id" - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitManufacturer @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $api= "/api/v1/manufacturers/$id" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitManufacturer @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitModel.ps1 b/SnipeitPS/Public/Get-SnipeitModel.ps1 index 231040c..d28f4ea 100644 --- a/SnipeitPS/Public/Get-SnipeitModel.ps1 +++ b/SnipeitPS/Public/Get-SnipeitModel.ps1 @@ -60,58 +60,64 @@ function Get-SnipeitModel() { [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $api = "/api/v1/models" + $api = "/api/v1/models" - if ($search -and $id ) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " - } - - if ($id) { - $api= "/api/v1/models/$id" - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitModel @callargs - $res - if ($res.count -ne $limit ) { - break - } - $offstart = $offstart + $limit + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $api= "/api/v1/models/$id" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitModel @callargs + $res + if ($res.count -ne $limit ) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitStatus.ps1 b/SnipeitPS/Public/Get-SnipeitStatus.ps1 index 49f5d44..6eb4b05 100644 --- a/SnipeitPS/Public/Get-SnipeitStatus.ps1 +++ b/SnipeitPS/Public/Get-SnipeitStatus.ps1 @@ -59,59 +59,64 @@ function Get-SnipeitStatus() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $api = "/api/v1/statuslabels" - $api = "/api/v1/statuslabels" - - if ($search -and $id ) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " - } - - if ($id) { - $api= "/api/v1/statuslabels/$id" - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitStatus @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $api= "/api/v1/statuslabels/$id" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitStatus @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitSupplier.ps1 b/SnipeitPS/Public/Get-SnipeitSupplier.ps1 index 302160d..d9de61b 100644 --- a/SnipeitPS/Public/Get-SnipeitSupplier.ps1 +++ b/SnipeitPS/Public/Get-SnipeitSupplier.ps1 @@ -59,59 +59,64 @@ function Get-SnipeitSupplier() { [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $api = "/api/v1/suppliers" + $api = "/api/v1/suppliers" - if ($search -and $id ) { - Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " - } - - if ($id) { - $api= "/api/v1/suppliers/$id" - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitSupplier @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + if ($search -and $id ) { + Throw "[$($MyInvocation.MyCommand.Name)] Please specify only -search or -id parameter , not both " + } + + if ($id) { + $api= "/api/v1/suppliers/$id" + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitSupplier @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result + } + } + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/Get-SnipeitUser.ps1 b/SnipeitPS/Public/Get-SnipeitUser.ps1 index 0c3dae1..130d027 100644 --- a/SnipeitPS/Public/Get-SnipeitUser.ps1 +++ b/SnipeitPS/Public/Get-SnipeitUser.ps1 @@ -97,53 +97,58 @@ function Get-SnipeitUser() { [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - switch ($PsCmdlet.ParameterSetName) { - 'Search' { $api = "/api/v1/users"} - 'Get with id' {$api= "/api/v1/users/$id"} - 'Get users a specific accessory id has been checked out to' {$api= "/api/v1/accessories/$accessory_id/checkedout"} - } - - $Parameters = @{ - Api = $api - Method = 'Get' - GetParameters = $SearchParameter - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($all) { - $offstart = $(if ($offset) {$offset} Else {0}) - $callargs = $SearchParameter - $callargs.Remove('all') - - while ($true) { - $callargs['offset'] = $offstart - $callargs['limit'] = $limit - $res=Get-SnipeitUser @callargs - $res - if ($res.count -lt $limit) { - break - } - $offstart = $offstart + $limit + $SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + switch ($PsCmdlet.ParameterSetName) { + 'Search' { $api = "/api/v1/users"} + 'Get with id' {$api= "/api/v1/users/$id"} + 'Get users a specific accessory id has been checked out to' {$api= "/api/v1/accessories/$accessory_id/checkedout"} + } + + $Parameters = @{ + Api = $api + Method = 'Get' + GetParameters = $SearchParameter + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } + } + process { + if ($all) { + $offstart = $(if ($offset) {$offset} Else {0}) + $callargs = $SearchParameter + $callargs.Remove('all') + + while ($true) { + $callargs['offset'] = $offstart + $callargs['limit'] = $limit + $res=Get-SnipeitUser @callargs + $res + if ($res.count -lt $limit) { + break + } + $offstart = $offstart + $limit + } + } else { + $result = Invoke-SnipeitMethod @Parameters + $result } - } else { - $result = Invoke-SnipeitMethod @Parameters - $result } - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitAccessory.ps1 b/SnipeitPS/Public/New-SnipeitAccessory.ps1 index f02467a..bbd03c3 100644 --- a/SnipeitPS/Public/New-SnipeitAccessory.ps1 +++ b/SnipeitPS/Public/New-SnipeitAccessory.ps1 @@ -115,40 +115,44 @@ function New-SnipeitAccessory() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + 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") + $Parameters = @{ + Api = "/api/v1/accessories" + Method = 'POST' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - $Parameters = @{ - Api = "/api/v1/accessories" - Method = 'POST' - Body = $Values + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + $result } - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitAsset.ps1 b/SnipeitPS/Public/New-SnipeitAsset.ps1 index 8f6103c..1294958 100644 --- a/SnipeitPS/Public/New-SnipeitAsset.ps1 +++ b/SnipeitPS/Public/New-SnipeitAsset.ps1 @@ -144,55 +144,61 @@ function New-SnipeitAsset() { [hashtable] $customfields ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - if ($values['purchase_date']) { - $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") - } - - if ($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 } } + if ($values['purchase_date']) { + $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") } - #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')} + if ($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 = @{ + Api = "/api/v1/hardware" + Method = 'Post' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - $Parameters = @{ - Api = "/api/v1/hardware" - Method = 'Post' - Body = $Values + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitAssetMaintenance.ps1 b/SnipeitPS/Public/New-SnipeitAssetMaintenance.ps1 index 608d9cd..f732502 100644 --- a/SnipeitPS/Public/New-SnipeitAssetMaintenance.ps1 +++ b/SnipeitPS/Public/New-SnipeitAssetMaintenance.ps1 @@ -76,44 +76,49 @@ function New-SnipeitAssetMaintenance() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + if ($Values['start_date']) { + $Values['start_date'] = $Values['start_date'].ToString("yyyy-MM-dd") + } - if ($Values['start_date']) { - $Values['start_date'] = $Values['start_date'].ToString("yyyy-MM-dd") + if ($Values['completion_date']) { + $Values['completion_date'] = $Values['completion_date'].ToString("yyyy-MM-dd") + } + + + $Parameters = @{ + Api = "/api/v1/maintenances" + Method = 'Post' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - if ($Values['completion_date']) { - $Values['completion_date'] = $Values['completion_date'].ToString("yyyy-MM-dd") + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - - $Parameters = @{ - Api = "/api/v1/maintenances" - Method = 'Post' - Body = $Values - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitAudit.ps1 b/SnipeitPS/Public/New-SnipeitAudit.ps1 index b115d35..5f7abb5 100644 --- a/SnipeitPS/Public/New-SnipeitAudit.ps1 +++ b/SnipeitPS/Public/New-SnipeitAudit.ps1 @@ -35,41 +35,46 @@ function New-SnipeitAudit() { [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $Values = @{ + "location_id" = $location_id + } - $Values = @{ - "location_id" = $location_id + if ($PSBoundParameters.ContainsKey('tag')) { + $Values += @{"asset_tag" = $tag} + } + + $Parameters = @{ + Api = "/api/v1/hardware/audit" + Method = 'Post' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - if ($PSBoundParameters.ContainsKey('tag')) { - $Values += @{"asset_tag" = $tag} + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - $Parameters = @{ - Api = "/api/v1/hardware/audit" - Method = 'Post' - Body = $Values - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitCompany.ps1 b/SnipeitPS/Public/New-SnipeitCompany.ps1 index 69ca843..2cc07cb 100644 --- a/SnipeitPS/Public/New-SnipeitCompany.ps1 +++ b/SnipeitPS/Public/New-SnipeitCompany.ps1 @@ -41,36 +41,41 @@ function New-SnipeitCompany() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $Parameters = @{ + Api = "/api/v1/companies" + Method = 'POST' + Body = $Values + } - $Parameters = @{ - Api = "/api/v1/companies" - Method = 'POST' - Body = $Values + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitComponent.ps1 b/SnipeitPS/Public/New-SnipeitComponent.ps1 index f3d785f..08cdb72 100644 --- a/SnipeitPS/Public/New-SnipeitComponent.ps1 +++ b/SnipeitPS/Public/New-SnipeitComponent.ps1 @@ -76,40 +76,45 @@ function New-SnipeitComponent() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + 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") + $Parameters = @{ + Api = "/api/v1/components" + Method = 'POST' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - $Parameters = @{ - Api = "/api/v1/components" - Method = 'POST' - Body = $Values + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitConsumable.ps1 b/SnipeitPS/Public/New-SnipeitConsumable.ps1 index 3b9c8ce..c24704c 100644 --- a/SnipeitPS/Public/New-SnipeitConsumable.ps1 +++ b/SnipeitPS/Public/New-SnipeitConsumable.ps1 @@ -122,9 +122,7 @@ function New-SnipeitConsumable() { if ($Values['purchase_date']) { $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd") } - } - process { $Parameters = @{ Api = "/api/v1/consumables" Method = 'Post' @@ -140,7 +138,9 @@ function New-SnipeitConsumable() { Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." Set-SnipeitPSLegacyUrl -url $url } + } + process { if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { $result = Invoke-SnipeitMethod @Parameters } diff --git a/SnipeitPS/Public/New-SnipeitDepartment.ps1 b/SnipeitPS/Public/New-SnipeitDepartment.ps1 index 31a279f..1510303 100644 --- a/SnipeitPS/Public/New-SnipeitDepartment.ps1 +++ b/SnipeitPS/Public/New-SnipeitDepartment.ps1 @@ -60,36 +60,41 @@ function New-SnipeitDepartment() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $Parameters = @{ + Api = "/api/v1/departments" + Method = 'POST' + Body = $Values + } - $Parameters = @{ - Api = "/api/v1/departments" - Method = 'POST' - Body = $Values + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitLicense.ps1 b/SnipeitPS/Public/New-SnipeitLicense.ps1 index 9aee5fa..2f2ac28 100644 --- a/SnipeitPS/Public/New-SnipeitLicense.ps1 +++ b/SnipeitPS/Public/New-SnipeitLicense.ps1 @@ -123,48 +123,52 @@ function New-SnipeitLicense() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + 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") + } + + $Parameters = @{ + Api = "/api/v1/licenses" + Method = 'POST' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - if ($Values['purchase_date']) { - $Values['purchase_date'] = $Values['purchase_date'].ToString("yyyy-MM-dd") + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - - if ($Values['termination_date']) { - $Values['termination_date'] = $Values['termination_date'].ToString("yyyy-MM-dd") - } - - $Parameters = @{ - Api = "/api/v1/licenses" - Method = 'POST' - Body = $Values - } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitLocation.ps1 b/SnipeitPS/Public/New-SnipeitLocation.ps1 index 845417e..fa4d99a 100644 --- a/SnipeitPS/Public/New-SnipeitLocation.ps1 +++ b/SnipeitPS/Public/New-SnipeitLocation.ps1 @@ -93,34 +93,40 @@ function New-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 -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $Parameters = @{ - Api = "/api/v1/locations" - Method = 'post' - Body = $Values + $Parameters = @{ + Api = "/api/v1/locations" + Method = 'post' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitManufacturer.ps1 b/SnipeitPS/Public/New-SnipeitManufacturer.ps1 index 3005eca..3efb031 100644 --- a/SnipeitPS/Public/New-SnipeitManufacturer.ps1 +++ b/SnipeitPS/Public/New-SnipeitManufacturer.ps1 @@ -46,36 +46,40 @@ function New-SnipeitManufacturer() { [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $Values = @{ - "name" = $Name + $Values = @{ + "name" = $Name + } + + $Parameters = @{ + Api = "/api/v1/manufacturers" + Method = 'post' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } - $Parameters = @{ - Api = "/api/v1/manufacturers" - Method = 'post' - Body = $Values + $result } - - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitModel.ps1 b/SnipeitPS/Public/New-SnipeitModel.ps1 index bb1fda7..d198c39 100644 --- a/SnipeitPS/Public/New-SnipeitModel.ps1 +++ b/SnipeitPS/Public/New-SnipeitModel.ps1 @@ -66,43 +66,49 @@ function New-SnipeitModel() { [string]$apiKey ) - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - $Values = @{ - name = $name - category_id = $category_id - manufacturer_id = $manufacturer_id - fieldset_id = $fieldset_id + $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) } + + + $Parameters = @{ + Api = "/api/v1/models" + Method = 'post' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - if ($PSBoundParameters.ContainsKey('model_number')) { $Values.Add("model_number", $model_number) } - if ($PSBoundParameters.ContainsKey('eol')) { $Values.Add("eol", $eol) } + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } - - $Parameters = @{ - Api = "/api/v1/models" - Method = 'post' - Body = $Values + $result } - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitSupplier.ps1 b/SnipeitPS/Public/New-SnipeitSupplier.ps1 index 12d4f16..fdad3a4 100644 --- a/SnipeitPS/Public/New-SnipeitSupplier.ps1 +++ b/SnipeitPS/Public/New-SnipeitSupplier.ps1 @@ -96,36 +96,41 @@ function New-SnipeitSupplier() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + $Parameters = @{ + Api = "/api/v1/suppilers" + Method = 'POST' + Body = $Values + } - $Parameters = @{ - Api = "/api/v1/suppilers" - Method = 'POST' - Body = $Values + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } } diff --git a/SnipeitPS/Public/New-SnipeitUser.ps1 b/SnipeitPS/Public/New-SnipeitUser.ps1 index 0cd7841..ffdab44 100644 --- a/SnipeitPS/Public/New-SnipeitUser.ps1 +++ b/SnipeitPS/Public/New-SnipeitUser.ps1 @@ -116,39 +116,44 @@ function New-SnipeitUser() { [parameter(mandatory = $false)] [string]$apiKey ) + begin { + Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name - Test-SnipeitAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name + $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters - $Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters + if ($password ) { + $Values['password_confirmation'] = $password + } - if ($password ) { - $Values['password_confirmation'] = $password + $Parameters = @{ + Api = "/api/v1/users" + Method = 'post' + Body = $Values + } + + if ($PSBoundParameters.ContainsKey('apiKey')) { + Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyApiKey -apiKey $apikey + } + + if ($PSBoundParameters.ContainsKey('url')) { + Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." + Set-SnipeitPSLegacyUrl -url $url + } } - $Parameters = @{ - Api = "/api/v1/users" - Method = 'post' - Body = $Values + process { + if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result } - if ($PSBoundParameters.ContainsKey('apiKey')) { - Write-Warning "-apiKey parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyApiKey -apiKey $apikey - } - - if ($PSBoundParameters.ContainsKey('url')) { - Write-Warning "-url parameter is deprecated, please use Connect-SnipeitPS instead." - Set-SnipeitPSLegacyUrl -url $url - } - - if ($PSCmdlet.ShouldProcess("ShouldProcess?")) { - $result = Invoke-SnipeitMethod @Parameters - } - - $result - - # reset legacy sessions - if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { - Reset-SnipeitPSLegacyApi + end { + # reset legacy sessions + if ($PSBoundParameters.ContainsKey('url') -or $PSBoundParameters.ContainsKey('apiKey')) { + Reset-SnipeitPSLegacyApi + } } }