Hi I am quite new to Powershell but I have one niggling question. I want to be able to tell if a command has completed successfully so I can give meaningful messages to host.
I am using the appcmd
command to add a binding in IIS. Essentially that goes as follows:
./appcmd set site /site.name:........................
But how can I do a check to ensure it was successful or not?
I think if I just put Write-Host "Successfully added binding"
after that statement it will fire after regardless if the appcmd
was successful.
I'm guessing I need to do something like:
$successful = ./appcmd set site /site.name:........................
but then $successful
seems to be a string containing the msg result?
Grateful any help on this! Cheers
$?
and$LastExitCode
are relative? Suppose I execute this (or another) cmd throughout the script- those vars are relative to the last command that was executed? – Inexperience