Invoke-WebRequest in PowerShell form

Using PowerShell Studio… I’ve created a form that pulls warranty info from Dell’s website. The click event runs the following…

$apikey = "(redacted)"
$serial = $textboxSerialNumber.Text
[xml]$XML = (Invoke-WebRequest -Uri "https://api.dell.com/support/v2/assetinfo/warranty/tags.xml?apikey=$apikey&svctags=$serial")
$datetimepickerPurchaseDate.Text = Get-Date $XML.GetAssetWarrantyResponse.GetAssetWarrantyResult.Response.DellAsset.ShipDate -Format d

If I run it as a PSF from PowerShell studio if returns the date. If I build it and run it as an EXE I get the following error.

Invoke-WebRequest : Unable to connect to the remote server At line:292 char:18 + ... xml]$XML = (Invoke-WebRequest -Uri "https://api.dell.com/support/v2/a ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt pWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe ll.Commands.InvokeWebRequestCommand

Any ideas?

It could be a Windows Firewall setting. Once you’re running an EXE, you appear to the firewall as a distinct process, so it might be blocking outbound access. But you’d have to ask SAPIEN if there might be any other differences between running as a packaged EXE.

Aaaaand I’m gonna edit out your API key.

Thanks Don. That was the first thing I thought of. No bueno. :frowning:

My bad on the key. That’s one Dell makes publicly available for use with their api so I didn’t think about it. :slight_smile:

If it’s not the firewall, it’s antivirus… facepalm.