Invoke-WebRequest in PowerShell form

Welcome Forums General PowerShell Q&A Invoke-WebRequest in PowerShell form

This topic contains 3 replies, has 2 voices, and was last updated by

3 years, 3 months ago.

  • Author
  • #34324

    Topics: 3
    Replies: 12
    Points: 2
    Rank: Member

    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 "$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 " ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt
    pWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe

    Any ideas?

  • #34326

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

    Topics: 3
    Replies: 12
    Points: 2
    Rank: Member

    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

    Topics: 3
    Replies: 12
    Points: 2
    Rank: Member

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

The topic ‘Invoke-WebRequest in PowerShell form’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort