The Taco Bell jingle has lived rent free in my head for 20 years now
Father, author, blogger, enthusiast of all things PowerShell and automation. http://linktr.ee/mdowst
The Taco Bell jingle has lived rent free in my head for 20 years now
Thanks! That’s why it takes so long between my videos coming out. That and I have a full time job, 2 kids, coach my daughter’s soccer team, and suck at video editing.
Mine is definitely a passion project. I make videos on automation using PowerShell. I aim to make videos that teach the thought process and fundamentals and not just step by step tutorials. I’ve been busy moving halfway across the country but plan to start uploading some more once I’m settled in two weeks.
Just looking at it from the point of view of making the script more portable and easier for someone else to run, there are a few things I would address.
The first is the Write-Host
commands all over the script. I would recommend converting those to Write-Verbose
. Here is a great explanation when to use Write-Host
vs other outputs.
There are also numerous Write-Output
commands in the script. Anything sent to the Write-Output
will be returned to the calling console. If you need to take additional actions based on the results of this script, this could cause issues. You can run into problems with the New-Item
commands in there too, as they will produce output. You might consider saving them to a variable or piping to Out-Null
.
Also, there is no need to call exit and set an exit code in the way you are. If you want to write and error but have the script continue you can use, Write-Error
. If you want the processing to terminate then use throw
. Doing it this way will allow PowerShell’s built-in error handling to take care of the exit codes. It will also give you greater flexibility with using Error Action Preferences and using try/catch statements.
Finally, you have a path hardcoded for the workingDir. I would suggest making this a parameter or using an environment variable as this will make it more portable. Also, when creating the log variable, you will want to use the Join-Path cmdlet instead of just joining strings.
Either my wife or I will bust out “Bye, Felicia” at least once a week.