Reputation: 11
The issue is that I got a script from a vendor to pull data from a DB. The script is having a problem with the Invoke-WebRequest Section.
Here is the Script:
$url = @'
https://demo.liquidwarelabs.com/lwl/api?json={"inspector":"0","basis":"users","date":"yesterday","limit":"0","columns":"user_name,login_count","output":"1:html","header":"1"}
'@
$output = "c:\export\Tier1\view1.csv"
Invoke-WebRequest $url -OutFile $output
Here is the Error I get:
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send. At C:\Scripts\3.ps1:38 char:1 + Invoke-WebRequest $url -OutFile $output + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Upvotes: 1
Views: 10779
Reputation: 4835
You probably need to URL encode the JSON:
$url = 'https://demo.liquidwarelabs.com/lwl/api?json='
$json = '{"inspector":"0","basis":"users","date":"yesterday","limit":"0","columns":"user_name,login_count","output":"1:html","header":"1"}'
$encodedjson = [System.Web.HttpUtility]::UrlEncode($json)
$output = "c:\export\Tier1\view1.csv"
Invoke-WebRequest ($url+$encodedjson) -OutFile $output
Upvotes: 0