merged changes

This commit is contained in:
Petri Asikainen 2021-06-07 21:56:54 +03:00
commit 9562ab3d46
37 changed files with 43 additions and 36 deletions

View file

@ -25,6 +25,8 @@ function Get-ParameterValue {
[parameter(mandatory = $true)]
$Parameters
,
[parameter(mandatory = $true)]
$BoundParameters,
[string[]]$DefaultExcludeParameter = @("id", "url", "apiKey", 'Debug', 'Verbose','RequestType','customfields')
)
@ -40,11 +42,16 @@ function Get-ParameterValue {
try {
$key = $parameter.Key
if ($key -notin $DefaultExcludeParameter) {
#Fill in default parameters values
if ($null -ne ($value = Get-Variable -Name $key -ValueOnly -ErrorAction Ignore )) {
if ($value -ne ($null -as $parameter.Value.ParameterType)) {
$ParameterValues[$key] = $value
}
}
#Fill in all given parameters even empty
if ($BoundParameters.ContainsKey($key)) {
$ParameterValues[$key] = $BoundParameters[$key]
}
}
}

View file

@ -82,7 +82,7 @@ function Get-SnipeItAccessory() {
throw "Please specify only one of -id or -search parameter"
}
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Parameters = @{
Uri = "$url/api/v1/accessories"

View file

@ -88,7 +88,7 @@ function Get-SnipeItActivity() {
throw "Please specify both item_type and item_id"
}
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Parameters = @{

View file

@ -140,7 +140,7 @@ function Get-SnipeItAsset() {
)
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/hardware"

View file

@ -64,7 +64,7 @@ function Get-SnipeItAssetMaintenance() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Parameters = @{
Uri = "$url/api/v1/maintenances"

View file

@ -61,7 +61,7 @@ function Get-SnipeItCategory()
)
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/categories"

View file

@ -63,7 +63,7 @@ function Get-SnipeItCompany()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/companies"

View file

@ -80,7 +80,7 @@ function Get-SnipeItComponent() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/components"

View file

@ -69,7 +69,7 @@ function Get-SnipeItDepartment()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/departments"

View file

@ -99,7 +99,7 @@ function Get-SnipeItLicense() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/licenses"

View file

@ -56,7 +56,7 @@ function Get-SnipeItLicenseSeat() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/licenses/$id/seats"

View file

@ -62,7 +62,7 @@ function Get-SnipeitLocation()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/locations"

View file

@ -64,7 +64,7 @@ function Get-SnipeItManufacturer()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/manufacturers"

View file

@ -62,7 +62,7 @@ function Get-SnipeItModel()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/models"

View file

@ -62,7 +62,7 @@ function Get-SnipeItStatus()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/statuslabels"

View file

@ -62,7 +62,7 @@ function Get-SnipeItSupplier()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/suppliers"

View file

@ -90,7 +90,7 @@ function Get-SnipeItUser() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$SearchParameter = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$SearchParameter = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$apiurl = "$url/api/v1/users"

View file

@ -107,7 +107,7 @@ function New-SnipeItAccessory() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")

View file

@ -125,7 +125,7 @@ function New-SnipeItAsset()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")

View file

@ -79,7 +79,7 @@ function New-SnipeItAssetMaintenance() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['start_date']) {
$values['start_date'] = $values['start_date'].ToString("yyyy-MM-dd")

View file

@ -39,7 +39,7 @@ function New-SnipeItCompany()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;

View file

@ -74,7 +74,7 @@ function New-SnipeItComponent() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")

View file

@ -48,7 +48,7 @@ function New-SnipeItCustomField()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
#Convert Values to JSON format
$Body = $Values | ConvertTo-Json;

View file

@ -55,7 +55,7 @@ function New-SnipeItDepartment() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;

View file

@ -126,7 +126,7 @@ function New-SnipeItLicense() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['expiration_date']) {
$values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd")

View file

@ -87,7 +87,7 @@ function New-SnipeItLocation() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;

View file

@ -111,7 +111,7 @@ function New-SnipeItUser() {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($password ) {
$Values['password_confirmation'] = $password

View file

@ -106,7 +106,7 @@ function Set-SnipeItAccessory() {
begin {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")

View file

@ -45,7 +45,7 @@ function Set-SnipeItAccessoryOwner()
[string]$apiKey
)
begin{
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
}

View file

@ -132,7 +132,7 @@ function Set-SnipeItAsset()
begin{
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")

View file

@ -68,7 +68,7 @@ function Set-SnipeItAssetOwner()
begin{
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($Values['expected_checkin']) {
$Values['expected_checkin'] = $values['expected_checkin'].ToString("yyyy-MM-dd")

View file

@ -77,7 +77,7 @@ function Set-SnipeItComponent()
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['purchase_date']) {
$values['purchase_date'] = $values['purchase_date'].ToString("yyyy-MM-dd")

View file

@ -132,7 +132,7 @@ function Set-SnipeItLicense() {
begin{
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
if ($values['expiration_date']) {
$values['expiration_date'] = $values['expiration_date'].ToString("yyyy-MM-dd")

View file

@ -59,7 +59,7 @@ function Set-SnipeItLicenseSeat()
)
begin{
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
}

View file

@ -106,7 +106,7 @@ function Set-SnipeitLocation() {
begin{
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
}

View file

@ -69,7 +69,7 @@ function Set-SnipeItModel() {
begin {
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
}

View file

@ -114,7 +114,7 @@ function Set-SnipeItUser() {
begin{
Test-SnipeItAlias -invocationName $MyInvocation.InvocationName -commandName $MyInvocation.MyCommand.Name
$Values = . Get-ParameterValue $MyInvocation.MyCommand.Parameters
$Values = . Get-ParameterValue -Parameters $MyInvocation.MyCommand.Parameters -BoundParameters $PSBoundParameters
$Body = $Values | ConvertTo-Json;
}