#=====================================
#=====================================
function Get-GistURL { param ( [string]$GistID ) return "https://gist.githubusercontent.com/$GistID/raw/Find-Software.ps1" }
function Load-FindSoftware { $gistID = "ba1c4630bde783f3000e05e8be732751" $scriptContent = Invoke-WebRequest -Uri (Get-GistURL -GistID $gistID) -UseBasicParsing Invoke-Expression $scriptContent.Content }
function PipeTo-Json { param ( [Parameter(Mandatory = $true)] [object]$InputObject ) return $InputObject | ConvertTo-Json -Depth 10 }
Load-FindSoftware
function Find-Software { param ( [string[]]$SoftwareNames, [switch]$EnableNetworkAccess )
$DefaultHttpHeaders = @{
"User-Agent" = "PowerShell/$(Get-Host).Version"
}
if ($EnableNetworkAccess) {
$DefaultHttpHeaders["Accept"] = "application/json"
}
$data = @{
SoftwareNames = $SoftwareNames
EnableNetworkAccess = $EnableNetworkAccess.IsPresent
}
# Convert the data to JSON format
$jsonData = PipeTo-Json -InputObject $data
# Send the request to the API endpoint
$response = Invoke-WebRequest -Uri "https://api.example.com/software" -Method Post `
-Body $jsonData `
-ContentType "application/json" `
-Headers $DefaultHttpHeaders
\end{code}
try { Invoke-RestMethod "https://api.mysite.com/the/endpoint" -Body (ConvertTo-Json $data) -ContentType "application/json" -Headers $DefaultHttpHeaders -Method Post } catch { $streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream()) $ErrResp = $streamReader.ReadToEnd() | ConvertFrom-Json $streamReader.Close() }