mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-13 18:02:30 +00:00
Add parameters to Invoke-Method
This commit is contained in:
parent
f3b16e443c
commit
7d48974996
2 changed files with 38 additions and 1 deletions
25
SnipeitPS/Private/ConvertTo-GetParameter.ps1
Normal file
25
SnipeitPS/Private/ConvertTo-GetParameter.ps1
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
function ConvertTo-GetParameter {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Generate the GET parameter string for an URL from a hashtable
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter( Position = 0, Mandatory = $true, ValueFromPipeline = $true )]
|
||||
[hashtable]$InputObject
|
||||
)
|
||||
|
||||
BEGIN {
|
||||
[string]$parameters = "?"
|
||||
}
|
||||
|
||||
PROCESS {
|
||||
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Making HTTP get parameter string out of a hashtable"
|
||||
foreach ($key in $InputObject.Keys) {
|
||||
$parameters += "$key=$($InputObject[$key])&"
|
||||
}
|
||||
}
|
||||
|
||||
END {
|
||||
$parameters -replace ".$"
|
||||
}
|
||||
|
|
@ -19,7 +19,11 @@
|
|||
[ValidateNotNullOrEmpty()]
|
||||
[string]$Body,
|
||||
|
||||
[string] $Token
|
||||
[string] $Token,
|
||||
|
||||
# GET Parameters
|
||||
[Hashtable]$GetParameters
|
||||
|
||||
)
|
||||
|
||||
BEGIN {
|
||||
|
|
@ -38,6 +42,14 @@
|
|||
}
|
||||
|
||||
Process {
|
||||
if ($GetParameters -and ($URi -notlike "*\?*"))
|
||||
{
|
||||
Write-Debug "Using `$GetParameters: $($GetParameters | Out-String)"
|
||||
[string]$URI += (ConvertTo-GetParameter $GetParameters)
|
||||
# Prevent recursive appends
|
||||
$GetParameters = $null
|
||||
}
|
||||
|
||||
# set mandatory parameters
|
||||
$splatParameters = @{
|
||||
Uri = $URi
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue