I have a great success of using Invoke-HKCURegistrySettingsForAllUsers so far and it always worked like a charm. I have a new use case to add these User Keys where value section also needs currently logged on user name. I’ve tried couple of things but did not get expected result for me. Any way to achieve this?
[scriptblock]$HKCURegistrySettings = {
Set-RegistryKey -Key 'HKCU\Software\ABC\XYZ' -Name 'AAA' -Value "C:\Users\%UserName%/Documents/A1/A2" -Type String -SID $UserProfile.SID
Set-RegistryKey -Key 'HKCU\Software\ABC\XYZ' -Name 'BBB' -Value "C:\Users\%UserName%/Documents/B1/B2" -Type String -SID $UserProfile.SID
Set-RegistryKey -Key 'HKCU\Software\ABC\XYZ' -Name 'CCC' -Value "C:\Users\%UserName%/Documents" -Type String -SID $UserProfile.SID
Set-RegistryKey -Key 'HKCU\Software\ABC\XYZ' -Name 'DDD' -Value "C:\Users\%UserName%/Documents/D1/D2" -Type String -SID $UserProfile.SID
}
Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings