Github에서 가져온 Powershell 스크립트를 사용하여 데이터를 Ducksboard 대시 보드에 넣으려고합니다. 이 함수는 훌륭하게 작동하지만 데이터의 일부로 변수를 제공해야합니다. 실제 값을 푸시하는 함수 아래에 포함 된 함수에 대한 두 번의 호출 중 44 개가 잘 작동하지만, 변수 $ qtybord로 대체하면 함수가 넘어집니다. 나는 단일 따옴표 안에있는 var를 극복하기 위해 여러 옵션을 시도했지만 작동하도록 할 수는 없습니다. 아무도 도와 줄 수 있습니까?Powershell API Postuable to Ducksboard
# Squirt data to Duscksboard
function Execute-DucksboardApi
{
param(
[string] $url = $null,
[string] $data = $null,
[string] $apikey = $null,
[string] $contentType = "application/json",
[string] $codePageName = "UTF-8",
[string] $userAgent = $null
);
if ($url -and $data -and $apikey)
{
[System.Net.WebRequest]$webRequest = [System.Net.WebRequest]::Create($url);
$webRequest.ServicePoint.Expect100Continue = $false;
[System.Net.NetworkCredential]$credentials = New-Object System.Net.NetworkCredential($apikey, 'ignored');
$webRequest.Credentials = $credentials.GetCredential($url, 'Basic');
$webRequest.PreAuthenticate = $true;
$webRequest.ContentType = $contentType;
$webRequest.Method = "POST";
if ($userAgent)
{
$webRequest.UserAgent = $userAgent;
}
$enc = [System.Text.Encoding]::GetEncoding($codePageName);
[byte[]]$bytes = $enc.GetBytes($data);
$webRequest.ContentLength = $bytes.Length;
[System.IO.Stream]$reqStream = $webRequest.GetRequestStream();
$reqStream.Write($bytes, 0, $bytes.Length);
$reqStream.Flush();
$resp = $webRequest.GetResponse();
$rs = $resp.GetResponseStream();
[System.IO.StreamReader]$sr = New-Object System.IO.StreamReader -argumentList $rs;
$sr.ReadToEnd();
}
}
$qtybord = 44
Execute-DucksboardApi -url 'https://push.ducksboard.com/v/123752/' -data '{"value": $qtybord}' -apikey 'tu2j3d3epqytWZD1haHnjJSJ1NqBrmvPe5SONc0VYge4BbIPi0'
Execute-DucksboardApi -url 'https://push.ducksboard.com/v/123752/' -data '{"value": 44}' -apikey 'tu2j3d3epqytWZD1haHnjJSJ1NqBrmvPe5SONc0VYge4BbIPi0'
*
환상적인 :이 같은 뭔가 재생할 수 있습니다 V3 당신이 PowerShell을 있다면 또한
. 정말 고맙습니다!!! – Gebraffe
@Gebraffe 도움을 기쁩니다! –