< Back

Invoke-CommandWithRetries

Sat Jan 18, 2020 9:44 pm

NAME Invoke-CommandWithRetries



SYNOPSIS

Calls a shell (cmd) command with retries





SYNTAX

Invoke-CommandWithRetries [-Command] <String> [[-Arguments] <Array>] [[-TrustExitCode] <Boolean>]

[[-RetrySleepSeconds] <Int32>] [[-MaxAttempts] <Int32>] [[-PrintCommand] <Boolean>] [[-PrintOutput] <Boolean>]

[[-AllowedReturnValues] <Int32[]>] [[-ErrorMessage] <String>] [<CommonParameters>]





DESCRIPTION

The Invoke-CommandWithRetries function calls shell (cmd) commands using the provided parameters, with optional

retries in configurable intervals upon failures.





PARAMETERS

-Command <String>

The command to call.



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Arguments <Array>

Arguments to pass when invoking the comand.



Required? false

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-TrustExitCode <Boolean>

Trust the command's exit code for the purpose of determining whether it was successful or not.

If this parameter is $False, a non-empty stderr will also be considered a failure.



Required? false

Position? 3

Default value True

Accept pipeline input? false

Accept wildcard characters? false



-RetrySleepSeconds <Int32>

Time in seconds to sleep between retry attempts in case of command failure.



Required? false

Position? 4

Default value 10

Accept pipeline input? false

Accept wildcard characters? false



-MaxAttempts <Int32>

Maximum number of retry attempts in case of command failure.



Required? false

Position? 5

Default value 10

Accept pipeline input? false

Accept wildcard characters? false



-PrintCommand <Boolean>

Determines whether or not to print the full command to the host before execution.



Required? false

Position? 6

Default value True

Accept pipeline input? false

Accept wildcard characters? false



-PrintOutput <Boolean>



Required? false

Position? 7

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-AllowedReturnValues <Int32[]>

An array of acceptable return codes (in addition to 0). If omitted only a return code of 0 is used to indicate

success.



Required? false

Position? 8

Default value @()

Accept pipeline input? false

Accept wildcard characters? false



-ErrorMessage <String>

A message to add include when the command has failed to be run.



Required? false

Position? 9

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

None. You cannot pipe objects to Call-CommandWithRetries.





OUTPUTS

The output of the last command execution.





-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Use cURL for Windows to download the latest NuGet command-line client



C:\\PS> Call-CommandWithRetries "curl.exe" @("--fail", "-O",

"https://dist.nuget.org/win-x86-commandl ... /nuget.exe")











RELATED LINKS