This commit is contained in:
Petri Asikainen 2021-01-29 18:08:19 +02:00
parent a5e691d8f0
commit 6828244dfa
27 changed files with 33 additions and 38 deletions

View file

@ -21,23 +21,21 @@ function Get-ParameterValue {
# } # }
[CmdletBinding()] [CmdletBinding()]
param( param(
# The $MyInvocation for the caller -- DO NOT pass this (dot-source Get-ParameterValues instead) # Pass $MyInvocation.MyCommand.Parameters to function, powershell 7 seems to only populate variables with dot sourcing
$Invocation = $MyInvocation, [parameter(mandatory = $true)]
# The $PSBoundParameters for the caller -- DO NOT pass this (dot-source Get-ParameterValues instead) $Parameters
$BoundParameters = $PSBoundParameters, ,
[string[]]$DefaultExcludeParameter = @("id", "url", "apiKey", 'Debug', 'Verbose') [string[]]$DefaultExcludeParameter = @("id", "url", "apiKey", 'Debug', 'Verbose')
) )
if ($MyInvocation.Line[($MyInvocation.OffsetInLine - 1)] -ne '.') { if ($MyInvocation.Line[($MyInvocation.OffsetInLine - 1)] -ne '.') {
throw "Get-ParameterValues must be dot-sourced, like this: . Get-ParameterValues" throw "Get-ParameterValue must be dot-sourced, like this: . Get-ParameterValues"
}
if ($PSBoundParameters.Count -gt 0) {
throw "You should not pass parameters to Get-ParameterValues, just dot-source it like this: . Get-ParameterValues"
} }
$ParameterValues = @{} $ParameterValues = @{}
foreach ($parameter in $Invocation.MyCommand.Parameters.GetEnumerator()) { foreach ($parameter in $Parameters.GetEnumerator()) {
# gm -in $parameter.Value | Out-Default # gm -in $parameter.Value | Out-Default
try { try {
$key = $parameter.Key $key = $parameter.Key
@ -48,9 +46,6 @@ function Get-ParameterValue {
} }
} }
if ($BoundParameters.ContainsKey($key)) {
$ParameterValues[$key] = $BoundParameters[$key]
}
} }
} }
finally {} finally {}

View file

@ -60,7 +60,7 @@ function Get-Accessory() {
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/accessories" Uri = "$url/api/v1/accessories"

View file

@ -118,7 +118,7 @@ function Get-Asset() {
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/hardware" $apiurl = "$url/api/v1/hardware"

View file

@ -62,7 +62,7 @@ function Get-AssetMaintenance() {
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Parameters = @{ $Parameters = @{
Uri = "$url/api/v1/maintenances" Uri = "$url/api/v1/maintenances"

View file

@ -54,7 +54,7 @@ function Get-Category()
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/categories" $apiurl = "$url/api/v1/categories"

View file

@ -54,7 +54,7 @@ function Get-Company()
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/companies" $apiurl = "$url/api/v1/companies"

View file

@ -62,7 +62,7 @@ function Get-Component() {
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/components" $apiurl = "$url/api/v1/components"

View file

@ -57,7 +57,7 @@ function Get-Department()
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/departments" $apiurl = "$url/api/v1/departments"

View file

@ -79,7 +79,7 @@ function Get-License() {
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/licenses" $apiurl = "$url/api/v1/licenses"

View file

@ -54,7 +54,7 @@ function Get-Manufacturer()
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/manufacturers" $apiurl = "$url/api/v1/manufacturers"

View file

@ -54,7 +54,7 @@ function Get-Model()
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/models" $apiurl = "$url/api/v1/models"

View file

@ -54,7 +54,7 @@ function Get-SnipeitLocation()
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/locations" $apiurl = "$url/api/v1/locations"

View file

@ -54,7 +54,7 @@ function Get-Status()
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/statuslabels" $apiurl = "$url/api/v1/statuslabels"

View file

@ -54,7 +54,7 @@ function Get-Supplier()
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/suppliers" $apiurl = "$url/api/v1/suppliers"

View file

@ -60,7 +60,7 @@ function Get-User() {
[string]$apiKey [string]$apiKey
) )
$SearchParameter = . Get-ParameterValue $SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$apiurl = "$url/api/v1/users" $apiurl = "$url/api/v1/users"

View file

@ -41,7 +41,7 @@ function New-Accessory() {
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['purchase_date']) { if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")

View file

@ -36,7 +36,7 @@ function New-AssetMaintenance() {
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['start_date']) { if ($values['start_date']) {
$values['start_date'] = $values['start_date'].ToString("yyyy-MM-dd") $values['start_date'] = $values['start_date'].ToString("yyyy-MM-dd")

View file

@ -39,7 +39,7 @@ function New-Company()
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;

View file

@ -58,7 +58,7 @@ function New-Component() {
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['purchase_date']) { if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")

View file

@ -46,7 +46,7 @@ function New-CustomField()
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
#Convert Values to JSON format #Convert Values to JSON format
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;

View file

@ -52,7 +52,7 @@ function New-Department() {
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;

View file

@ -56,7 +56,7 @@ function New-License() {
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['expiration_date']) { if ($values['expiration_date']) {
$values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd") $values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd")

View file

@ -58,7 +58,7 @@ function New-Location() {
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;

View file

@ -41,7 +41,7 @@ function Set-Accessory() {
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['purchase_date']) { if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd") $values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")

View file

@ -58,7 +58,7 @@ function Set-License() {
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($values['expiration_date']) { if ($values['expiration_date']) {
$values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd") $values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd")

View file

@ -31,7 +31,7 @@ function Set-Model() {
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;

View file

@ -82,7 +82,7 @@ function Set-SnipeitLocation() {
[string]$apiKey [string]$apiKey
) )
$Values = . Get-ParameterValue $Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;