Seems like every time I cobble up a Powershell solution to a problem, along comes some wise guy who shows me I did it the hard way. Thanks - like it or not you've made my job a little easier today, but don't tell my boss, he likes to see me sweating over complex solutions!
at the start of my $Profile, which is pretty much the same as
Set-StrictMode -version 1.0
(I used Set-PSDebug because I didn't know about Set-StrictMode back then 🙂 )
This has saved me significant amounts of time that I used to waste tracking down mis-typed variable names. After reading the article I've updated $Profile to use strict mode version 2.0, that'll help out even more.+
To the readers: Check out Set-PSDebug if you haven't - it can be set to display variable assignments, function calls, etc when the script runs. Sometimes too much information is presented, but if you have a problem code section, turn it on for that section then turn it off afterward until you get the kinks worked out.
We're in a somewhat restricted environment, so WMI is allowed but WinRM isn't running on the remote machines. We have to make use of WMI but do it through PowerShell commandlets. It works well without the need to install any 3rd part tools (which can only be done after a long and laborious vetting and approval process).