Powershell script best practices #4- Powershell Error handling with Try-Catch
Below are few more PS best practices :- ps-click on links for more detail about each topic.
1> Comments -> Always use comments to explain code .. click for more detail
2> powershell logging –> log all possible detail to throubleshooting the script or check the script execution history.
3> Error handling -> custom and system error handling with with try-catch
4> Functions -> Powershell function to avoid duplicate code
5> Parameters or User-defined variables -> No Hard-Coding so better to keep all input as parameters for functions or Place user-defined variables at top of script in case required.
6> #regions -> Grouping of code with regions for easy reading and troubleshooting
7> beautify/ Auto indent powershell -> beautify and auto indent powershell code with visual studio code