lundi 9 octobre 2017

Powershell script - check for exit code

Hi I have the following script:

foreach ($server in $ProductList.$SelectedServer){

Invoke-Command -ComputerName $server -Credential domain\user -ScriptBlock {

Import-Module WebAdministration
echo "restarting AppPool $args[0] ... on $args[1]"
Restart-WebAppPool -Name $args[0] -ErrorAction stop
echo "Restarted WebApp $args[0] on $args[1]"}
} -ArgumentList $SelectedAppPool, $Server

I would like to check if the Restart-WebAppPool command executes successfully. If it does I echo 'it worked' else echo 'It did not work'.

The goal is to provide a simple plain english message rather than the typical unhandled exception.

Thanks

Aucun commentaire:

Enregistrer un commentaire