Set multiple registry values to all users HKCU profiles using PowerShell & Active Setup

This is a quick one – an improvement on an almost perfect script that doesn’t quite work how it should.
the script Set-RegistryValueForAllUsers.ps1 found on the TechNet Gallery has one major fault.

If you try and apply more than one value at a time, the last applied value is overwritten, leaving you at the end of the script with the last value and nothing else. Very simple change, but now the script works as intended.

I’ll be reaching out to the author later to see if we can get this rectified, but as there are many comments on the TechNet script page covering this, I figured I’d just put the fixed code up here for others to view.

As always, a copy of this code is available on my GitHub repository.

2 comments

  1. Matt Reply
    May 23, 2020 at 12:22 pm

    I love this script and it is perfect for what I need it to do but it doesn’t quite do it. I am trying to correct User Shell Folder locations that were corrupted by Redirected folders. The reason this script is perfect is because it has to add the value for HKCU for each user that signs on. However when I call the script and do the 4 Registry edits I need, it won’t pull in the currently logged on user. It just pulls the workstation name when I try to use $env:Username, %username% and other things. Sometimes in the seeder keys it creates it has nothing in the path, sometimes it shows the computer name. Here are my 5 edits….
    Set-RegistryValueForAllUsers -RegistryInstance @{‘Name’ = ‘Desktop’; ‘Type’ = ‘ExpandString’; ‘Value’ = “\\secendc01\RedirectedFolders$\'”$loggedonuser”‘\Desktop”; ‘Path’ = “Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders”}
    Set-RegistryValueForAllUsers -RegistryInstance @{‘Name’ = ‘Favorites’; ‘Type’ = ‘ExpandString’; ‘Value’ = “\\secendc01\RedirectedFolders$\'”$loggedonuser”‘\Favorites”; ‘Path’ = “Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders”}
    Set-RegistryValueForAllUsers -RegistryInstance @{‘Name’ = ‘Personal’; ‘Type’ = ‘ExpandString’; ‘Value’ = “\\secendc01\RedirectedFolders$\'”$loggedonuser”‘\My Documents”; ‘Path’ = “Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders”}
    Set-RegistryValueForAllUsers -RegistryInstance @{‘Name’ = ‘My Pictures’; ‘Type’ = ‘ExpandString’; ‘Value’ = “\\secendc01\RedirectedFolders$\'”$loggedonuser”‘\My Pictures”; ‘Path’ = “Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders”}

  2. Matt Montgomery Reply
    May 23, 2020 at 12:57 pm

    It seems that how I was adding those Registry edits that gets put into Active Setup end up hard coding that currently logged in user so it only fixes my issues for that one user. What I would ideally need, and I am not even sure if it is possible but to have it apply to all users when they logon but it has their path in the value so I may not be able to accomplish this.

Leave A Comment

Please be polite. We appreciate that. Your email address will not be published and required fields are marked