#11
Post
by Compo » 02 Sep 2021 20:40
Why did you change the code I provided? Whilst I'm all for having a particular style etc. I don't understand why you'd use a variation which defines a minimum of four, possibly five variables and uses two for loops, over one which defines only one variable and uses one for loop.
Additionally, your variation has potential pitfalls. For instance, if %__APPDIR__%wbem\WMIC.exe does not exist, the code will still run using an empty variable, and generate an error messaage, leaving an undefined netType variable. You should also remember that as MSFT_NetConnectionProfile is only available in versions of Windows which has WMIC.exe built-in, in that location, there should be no need to check for its existence. After all if it doesn't exist, then MSFT_NetConnectionProfile will not be available either.
My code was designed to define the output as Unknown, if the system does not have WMIC.exe in the default location, or if MSFT_NetConnectionProfile is not available in the OS.
I also understand that your question was not necessarily specific to running this one command, but if you had several commands which could only be performed in PowerShell, you should not have chosen one which could be performed without it, as a basis for making your point. WMIC.exe is a slow command utility to run, especially on its first usage, so I could probably have leveraged WMI using something faster like cscript.exe instead.