0 votes

I am setting up a custom script to do a remote web call (HTTP post) using Invoke-Webrequest.

I have it working, but how can I have Adaxes send an email or retry if the remote HTTP server is down or unreachable during the attempted call?

This is the error that would be output from a failed attempt in this case.

Unable to connect to the remote server. For example:

Invoke-WebRequest -URI someunreachable.com

The site has to have a valid DNS name obviously, but let's assume the site does but it is just unreachable for some reason (network, web services down, etc)

by (250 points)

1 Answer

0 votes
by (1.8k points)

Hello,

To send e-mail messages from scripts executed in Adaxes, you can use the SendMail method of the predefined $Context variable. To retry a web request for a certain number of attempts or until it is successful, you can use the following script. In the script:

$waitTimeInterval – specifies how many seconds will the script wait before the next attempt.

$retryCount – specifies the maximum number of attempts.

$waitTimeInterval = 5 # TODO: modify me
$retryCount = 10 # TODO: modify me

do
{
    try
    { 
        $response = Invoke-WebRequest -Uri "http://host.domain.com"
    }
    catch
    {
        $retryCount--
        Start-Sleep -Seconds $waitTimeInterval
    }
}
while ($response.StatusCode -ne 200 -and $retryCount -gt 0)

Please note, that by default, the timeout for PowerShell script execution in Adaxes is 10 minutes. For detailed information, please see https://www.adaxes.com/help/?ManageBusinessRules.IncreaseScriptTimeout.html.

Related questions

0 votes
1 answer

Hi, Is there anyway to get a listing of the currently running jobs? If not, feature request :) Also, when you update the web portal, one feature requested by some of ... (in IE), so users sometimes press multiple times thinking it has failed to run. regards

asked Jun 19, 2013 by firegoblin (11k points)
0 votes
1 answer

Given Scenario: Adaxes domain user is remote with his laptop and has adaxes self service client installed on Windows and is enrolled for self service via Adaxes. We ... get updated when a user initiates password reset/change password from the lock screen ?

asked Nov 2, 2020 by rsaran (250 points)
0 votes
1 answer

Hi Team, We would like to use security based questions and answers for password resets. I have found that we can force a user to answer certain questions when enrolling, but if ... . Is there a way to ensure that a question must be answered each time? Thanks,

asked May 19, 2020 by antondubek (1.9k points)
0 votes
1 answer

Hi All, I see that Adaxes uses a local SQLite database for logging. However when a user enrols for password resets using a question and answer based authentication, where is ... some more sensitive than others so I was just wondering how it is handled? Thanks,

asked Apr 15, 2020 by antondubek (1.9k points)
0 votes
1 answer

Dear Support, I have a PS script, which as result has a DataTable of assets assigned to user in external system. I would like to show this data in Web interface - ... Can you please advise how to properly show the DataTable in script based report? Thank you!

asked Jul 30, 2019 by Dmytro.Rudyi (4.1k points)
2,381 questions
2,137 answers
5,770 comments
187,038 users