Merge branch 'PetriAsi-issue#67-powershell7-compatibility' into develop

This commit is contained in:
Petri Asikainen 2021-05-16 08:11:33 +03:00
commit d52e63d2c9
29 changed files with 38 additions and 41 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -16,7 +16,7 @@
.PARAMETER Model_id
Model ID of the asset, this can be got using Get-Model
.PARAMETER last_checkout
Date the asset was last checked out
@ -82,7 +82,7 @@ function Set-Asset()
[string]$Status_id,
[string]$Model_id,
[DateTime]$last_checkout,
[int]$assigned_to,
@ -114,7 +114,9 @@ function Set-Asset()
[hashtable] $customfields
)
$Values = . Get-ParameterValue
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
if ($model_id) { $Values.Add('model_id',$model_id)}
if ($customfields)
{

View file

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

View file

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

View file

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

Binary file not shown.