Invoke-WebRequest in PowerShell form

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Joshua Taylor Joshua Taylor 10 months, 1 week ago.

  • Author
    Posts
  • #34324
    Profile photo of Joshua Taylor
    Joshua Taylor
    Participant

    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?

  • #34326
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #34327
    Profile photo of Joshua Taylor
    Joshua Taylor
    Participant

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

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

  • #34385
    Profile photo of Joshua Taylor
    Joshua Taylor
    Participant

    If it's not the firewall, it's antivirus... facepalm.

You must be logged in to reply to this topic.