Father, author, blogger, enthusiast of all things PowerShell and automation. http://linktr.ee/mdowst
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.
ConvertTo-InteractiveHTML
function. Doug walks through generating HTML tables with sortable columns and customizing them using AI. Whether you’re managing large datasets or need a quick way to visualize your data, this tutorial will guide you through the process. Install the PSAI module and start making your data more dynamic.I remember before scrambling they just put blocks that prevented you from going to certain channels. I somehow figured out if you ran the cable box through the VCR first and put it on channel 2 while the TV was still on 3, it would shift all the channels down one. Cinemax was channel 14, which our box just would not go to. But it would go to 13, so doing my little trick teenage me got to watch a lot of skinamax.
It took me longer than I would have liked, but I did finally get the next video uploaded. I hope you enjoy it as well.
Nice write up, and a great primer for someone coming from the Linux/Bash world.
Thanks! I’d love to hear your thoughts once you’ve watched it.
Thanks! I’m glad to hear you are finding it useful.
Thanks! I’m glad to hear others are finding it useful.
Joel “Jaykul” Bennet is an opinionated DevOps engineer, programmer, speaker, and Microsoft MVP.
I love that description. I can’t wait to listen to it tonight!
Just a heads up, I received confirmation from the product team that the AZUREPS_HOST_ENVIRONMENT environment variable is going away. They are moving the backend to containers. Also, the COMPUTERNAME one that was always “client” is going to change too. The COMPUTERNAME will now be “Sandbox-###” with # being random numbers. I started using the code block below in my runbooks to find if they are running in Azure or hybrid worker/locally. It accounts for the current and the updates that will be rolling out in the near future.
$isHybridWorker = $true
if (($env:computername) -eq "CLIENT") {
$isHybridWorker = $false
}
elseif ($env:USERNAME -eq 'ContainerAdministrator') {
$isHybridWorker = $false
}
``
Typically, when I have a script I need to test locally, I’ll comment out the identity connection command and just authenticate outside of my script. If I’m feeling real fancy, I’ll write a try/catch to attempt to authenticate first as the managed identity then if it fails prompt me for credentials. Not the most elegant solution, but it works.
try {
Add-AzAccount -Identity -SubscriptionId $SubscriptionId -ErrorAction Stop | Out-Null
}
catch {
Add-AzAccount -SubscriptionId $SubscriptionId
}
The book I wrote. When I first talked with the publisher he asked, “what skills would you look for in someone who wants to do your job?” And that’s the premise I stuck with writing it.
From personal experience, it seems like things outside of your normal listening don’t affect too much. At least in my case, my daughter making me play the Encanto soundtrack 250,000 times hasn’t affected my weekly or daily playlists.
That’s pretty similar with what happened with me and the train. Kept getting random drops from a plant. I went out to investigate and everything tested perfect and the network was staying up. That was until a freight train rolled by. Turns out AT&T had run the line by shoving a piece of PVC through the gravel between two cross-ties, then running the cable through it.
No Azure DevOps automatically increments it every time you run the pipeline.