1
votes

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

1
Works for me. I get a response, though that response is a webpage with the text "Not Authorized" and "HTTP 403". Are you certain you don't have a proxy (or something else in your internet stack) interfering with the connection?Ryan Bemrose

1 Answers

0
votes

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