I am having a PowerShell script. It contains the logic of migrating files from file system to some cloud share. At the end of the script execution i.e. end of migration, I am exporting the log to csv file which contains data like whether file migrated with or with out error.
Now there can be situations where migration engineer stops the script manually using ctrl+Break or Shift+F5 or the script gets terminated due to some critical error.
Since my PowerShell code is generating a csv file at the end of successful execution, this interruption which is in between will not create any log file.
So I am in search of a PowerShell command or snippet which tells us that the code execution is stopped. And then we export the log file