# Cancel PowerShell Script Log

**URL:** <https://forums.powershell.org/t/cancel-powershell-script-log/19134>\
**Category:** PowerShell Help\
**Created:** [April 20, 2022, 5:26am UTC](https://forums.powershell.org/t/cancel-powershell-script-log/19134 "2022-04-20T05:26:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gokul](https://avatars.discourse-cdn.com/v4/letter/g/22d042/32.png) [@Gokul](https://forums.powershell.org/u/Gokul)\
**Post date:** [April 20, 2022, 5:26am UTC](https://forums.powershell.org/t/cancel-powershell-script-log/19134/1 "2022-04-20T05:26:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![steso555](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/steso555/32/2514_2.png) [@steso555](https://forums.powershell.org/u/steso555)\
**Post date:** [June 29, 2022, 2:11pm UTC](https://forums.powershell.org/t/cancel-powershell-script-log/19134/2 "2022-06-29T14:11:01Z")

</div>

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](https://devblogs.microsoft.com/powershell/errorlevel-equivalent/)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:17pm UTC](https://forums.powershell.org/t/cancel-powershell-script-log/19134/3 "2024-05-16T20:17:47Z")

</div>


