Today I implemented a function in the AppDeployToolkitExtensions.ps1 file. Every time i started the PSApp-Toolkit, I was surprised why the registry keys is not be set. I was looking for and found it in the 32bit hive of the registry.
The keys were only set correctly using the RegistryKey.CreateSubKey method. But why?
I admire the fact that you went as so far as to use [dotNet]: stuff while you are missing the point of using PSADT.
Using PSADT’s functions provides you with logging so that you can see what happened at install time. Using native PS commands you’d need a lot of extra code to give you that benefit.
PSADT has the Set-Registry function that will create the missing keys if they do not exist. It handles odd things like default registry values. And if it all goes to hell it will log the full error message to tell you WHY it blew up and stop the script, too!
All your code above would simply be:
Set-RegistryKey -Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Contoso1\test1' -Name 'test' -Value "01" -Type String
Set-RegistryKey -Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Contoso2\test1' -Name 'test' -Value "1" -Type String
Set-RegistryKey -Key 'HKEY_LOCAL_MACHINE\SOFTWARE\Contoso3\test1' -Name 'test' -Value "1" -Type String
Please check out the full manual in PSAppDeployToolkit.pdf or look at the functions defined in \AppDeployToolkit\AppDeployToolkitMain.ps1 to see what else is in PSADT.
As to what happened with your code, I’m guessing you ran the script in 32-bit powershell and the :Openkey from the first block doesn’t care about 32/64 stuff.