Cancel PowerShell Script Log

Hi Guys,

If someone cancels the Powershell Script while running ex by presssing Ctrl + C. Is there a way that we can get that captured and display it in the console? I want to log that user cancelled the script so that i get to know that script is cancelled not completed.

Have you tried using the $LASTEXITCODE variable? It will contain the exit code of the last .exe that was invoked. Take a look hier: ErrorLevel equivalent - PowerShell Team