I am working on a PowerShell function that is supposed to check if two values in the registry named “SQLArg4” and “SQLArg5” (or two other numbers) are set to a certain value content and set them if not.
The problem is I cannot enumerate the values to traverse through them to compare all of them and then add my two value contents if they are not present.
I tried creating a string out of “SQLArg” and a $i index but PowerShell would not allow me to use that string as a field of a variable.
Any ideas?
It sounds like you only need to work with one registry key (no recursion). Try this code. It will get all the values under $key that start with “SQLArgs” and store them in $values. It loops through a number sequence and tests for the existence of the key values named SQLArgs#. When it finds one it will set the key value data.