Hey everyone! I recently got a bit tired of updating my software and windows manually, so I created a PowerShell script that automates the process. It can update everything from Windows itself to various third-party apps using `winget`. I've put a lot of thought into it and I've even tested different scenarios, implementing notable feedback from you all and improving the structure of my script. I'd love to hear your thoughts on what I've done so far and any advice you can share to make it better! You can check out the script [here](https://github.com/twcau/UpdateMyWindowsMachine). Thanks in advance!
5 Answers
Some subjective feedback from me: avoid using `return` in your functions since it's considered an anti-pattern. Also, `Start-FirstTimeSetup` could be a hassle if someone needs to run it non-interactively. PWSH is case insensitive, so you might consider that for ease of use. And ensure that any external modules your script depends on are clearly indicated with a `#requires` statement!
By the way, winget has a native PowerShell module now; using that could save you from dealing with regex complications in your updates!
You might run into issues with winget. I remember having trouble with truncations in the update output when I tried something similar. Testing different outputs and possibly adjusting the PowerShell window width could help. Just a heads up!
For home use, your script seems fine, but I wouldn’t suggest it for enterprise environments. It’s clear you aimed this for personal use, but just make sure users are aware it’s not for large-scale deployments!
Thanks for sharing! A couple of things to consider: it's crucial to be cautious about linking personal info in scripts like this. You might want to refactor your script to use modules for easier management. Also, consider using parameter blocks instead of the outdated function syntax. Try to avoid inheriting variables from parent scopes, and ensure that error handling is set up correctly with an error action preference. These changes should lead to fewer bugs and clearer code. Good luck!
For function file based modules, what's the benefit over directly importing from the psm1 file? Just curious!
Thanks for the comprehensive feedback, CodeGuru89! I’ll definitely think more about structuring it better.
Exactly! I made it personal for home use and included a warning in the README to emphasize that point.