mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-13 09:52:30 +00:00
Merge branch 'PetriAsi-issue#67-powershell7-compatibility' into develop
This commit is contained in:
commit
d52e63d2c9
29 changed files with 38 additions and 41 deletions
|
|
@ -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 {}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ function Get-Accessory() {
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/accessories"
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ function Get-Asset() {
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
|
||||
$apiurl = "$url/api/v1/hardware"
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ function Get-AssetMaintenance() {
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$Parameters = @{
|
||||
Uri = "$url/api/v1/maintenances"
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ function Get-Category()
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/categories"
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ function Get-Company()
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/companies"
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ function Get-Component() {
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/components"
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ function Get-Department()
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/departments"
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ function Get-License() {
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/licenses"
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ function Get-Manufacturer()
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/manufacturers"
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ function Get-Model()
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/models"
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ function Get-SnipeitLocation()
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/locations"
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ function Get-Status()
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/statuslabels"
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ function Get-Supplier()
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/suppliers"
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ function Get-User() {
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$SearchParameter = . Get-ParameterValue
|
||||
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$apiurl = "$url/api/v1/users"
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ function New-Company()
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Values = . Get-ParameterValue
|
||||
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ function New-Department() {
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Values = . Get-ParameterValue
|
||||
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ function New-Location() {
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Values = . Get-ParameterValue
|
||||
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ function Set-Model() {
|
|||
[string]$apiKey
|
||||
)
|
||||
|
||||
$Values = . Get-ParameterValue
|
||||
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
|
||||
|
||||
$Body = $Values | ConvertTo-Json;
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
Loading…
Add table
Reference in a new issue