PowerShell Commands

Invoke-WebRequest

The Invoke-WebRequest cmdlet sends HTTP and HTTPS requests to a web page or web service.

GET Invoke-WebRequest

Sends a GET request and echo the response Content

$varUrl = "https://postman-echo.com/get"
Invoke-WebRequest -Method Get -Uri $varUrl -TimeoutSec 7200 | Select-Object -Expand Content

Sends a GET request and echo the response Status Code and Content

$varUrl = "https://postman-echo.com/get"

Try
{
    $response = Invoke-WebRequest -Method Get -Uri $varUrl -TimeoutSec 7200
    $response.StatusCode
    $response.Content
}
Catch
{
    $ErrorMessage = $_.Exception.Message
    Write-Output($ErrorMessage)
    $FailedItem = $_.Exception
    Write-Output($FailedItem)
    Break
}

POST Invoke-WebRequest

Sends a POST request and echo the response Content

Sends a POST request and echo the response Status Code and Content

Set Powershell to skip SSL certificate checks

If you are trying to query a web site and you have invalid SSL certificates, Powershell is by default very strict on what it accepts. You will often end up with errors like:

For the work around, try to run the script below before sending the invoke commands. This will ignore the ssl certificate error validation in the current PowerShell Session.

Reference

Last updated

Was this helpful?