Easily set a registry value for all user profiles on a system

Here's a very handy Powershell function that you can use in your scripts to set or add a registry value to every user hive on a computer.  Previously, if you needed to change a registry value in the HKEY_CURRENT_USER registry "hive" you had to both modify the value inside HKEY_US

 
 
 
 
 
4.9 Star
(10)
5,962 times
Add to favorites
11/6/2014
E-mail Twitter del.icio.us Digg Facebook
  • suggestions
    2 Posts | Last post September 04, 2018
    • It seems this script will remove all items in specified registry folder. Remove line 30+31 if you do not want that to happen.
      
      Note that using this script only existing user profiles are edited. To make defaults for newer logons, we have to load ntuser.dat file; see other blogs.
      
      Great script by the way, thanks!
      
    • little correction: this script does set correct settings for all users including new profiles profiles.
  • Errors when calling the function.
    2 Posts | Last post October 24, 2017
    • Set-RegistryValueForAllUsers -RegistryInstance @('Name'= 'Path'; 'Type'= 'string'; 'Value'= 'C:\\Hey Johnny\\'; 'Path' = 'HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Access\Security\Trusted Locations\Location0')
      
      Here are the errors.
      Invalid assignment expression. The left hand side of an assignment operator needs to be something that can be assigned to like a variable or a property.
      At line:1 char:56
      
      Invalid assignment expression. The left hand side of an assignment operator needs to be something that can be assigned to like a variable or a property.
      At line:1 char:72
      
      Invalid assignment expression. The left hand side of an assignment operator needs to be something that can be assigned to like a variable or a property.
      At line:1 char:91
      
      Invalid assignment expression. The left hand side of an assignment operator needs to be something that can be assigned to like a variable or a property.
      
      Help please?
    • use { instead of Parenthesis
  • Script kills Registry
    1 Posts | Last post September 13, 2016
    • If I try to set this Registry Key to 0 via the Command:
      
      Set-RegistryValueForAllUsers -RegistryInstance @{'Name' = 'SharingWizardOn'; 'Type' = 'DWord'; 'Value' = '0'; 'Path' = 'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced'}
      
      It kills all other Registry Keys in the Folder Advanced :-(((
  • Stuck and dont know why
    2 Posts | Last post April 05, 2016
    • Hi Guys.  Firstly, thank you for the script.  We were able to run it successfully to modify HKCU\Software\Microsoft\Internet Explorer\Main "Start Page"to a custom webpage value.  We also used the recommended addition by Exvitermin, as the whole key was being deleted.  
      
      Before running it with Exvitermin's recommended fix, it was not creating a key for all users, only the one logged in.  After running with Exvitermin's fix, it works for the logged in user, but it does not created the key for other profiles, instead, it creates an entire "Main" folder below the existing one,  named - Main" /v Start Page /t REG_SZ /d http://ourwebsitename.com /f", with no values in it.
      
      Any ideas would be a huge help.
    • I had a trailing backslash at the end of the key location that was creating the additional folder.  It appears to be working now, but only for the currently logged in user, not all the profiles on the machines.
  • Reg Key wiped?
    2 Posts | Last post March 28, 2016
    • I just ran this to change HKEY_USERS\Control Panel\Desktop entries (wallpaper and wallpaperstyle).  It worked fine except something major.  All other values in that registry key are now gone for the logged in user.  Other users updated correctly.
      
      Windows 7 x64 with WMF 5.0
      
      Any thoughts as to why?  It's kind of a deal-breaker to an otherwise excellent solution.
    • Ah... it's because of new-item with -force.  Even though the comment says "Create the key path if it doesn't exist" there's actually no test to see if it exists.  Thus -Force overwrites it.  Pretty significant error.
      
      Exvitermin pointed out a fix that I should have read before running this script. Buyer beware.
  • Split-Path -Parent sometimes results in empty string
    1 Posts | Last post February 01, 2016
    • Great Script, thank you!!
      
      I had the seldom case trying to add a key with this $instance.Path:
      Software\Microsoft\Windows\CurrentVersion\Internet Settings\P3P\History\127.0.0.1:8079
      
      with this $instance.Path the function Split-Path results in an empty string (maybe because of the colon), so I modified the line as follows:
      
      New-Item -Path ("HKU:\$sid\$($instance.Path)" | Split-Path -Parent) -Name ("HKU:\$sid\$($instance.Path)" | Split-Path -Leaf) -Force | Out-Null
      
      
  • Needed a little tweak for Powershell v2
    1 Posts | Last post January 06, 2016
    • On PowerShell V2 it needed a little tweak to work, I replaced this line:
       $LoggedOnSids = (Get-ChildItem HKU: | where { $_.Name -match 'S-\d-\d+-(\d+-){1,14}\d+$' }).PSChildName 
      
      With this:
      $LoggedOnSids = $(Get-ChildItem HKU: | where { $_.Name -match 'S-\d-\d+-(\d+-){1,14}\d+$' } | %{$_.Name})
  • Am I missing something?
    2 Posts | Last post December 22, 2015
    • Okay, maybe I am missing a step. When I try to dot this out and use your example just to verify. I get nothing. It just moves back to a cursor. I am running it in ISE. Am I missing a step? Any help would be appreciated.
      
      Thanks!
    • You'll need to either copy/paste this function into your session, or, when you dot source it, just call the function as you would any other.
  • Multiple runs of the function
    1 Posts | Last post November 05, 2015
    • Hi Adam,
      
      you should add a test for the path as adding an item clears the previous ones under the specified key.
      
      ## Create the key path if it doesn't exist
      If(!(Test-Path "HKU:\$sid\$($instance.Path)"))
      {
        New-Item -Path "HKU:\$sid\$($instance.Path | Split-Path -Parent)" -Name ($instance.Path | Split-Path -Leaf) -Force | Out-Null
      }
  • Applying values
    2 Posts | Last post May 07, 2015
    • I apologize for my scripting ignorance, but if I wanted to use this script to add a value to all users would I replace the "Active Setup" references to what I want that value to be, or would I have to add that after the function is completed?
      
      -Chris
    • I haven't tested it to add registry values but I think it should still work.  I'm using the "reg add" syntax to make it happen.  Check the example in the script and try it.  It should go something like  Set-RegistryValueForAllUsers -RegistryInstance @{'Name' = 'Setting'; 'Type' = 'String'; 'Value' = 'someval'; 'Path' = 'SOFTWARE\Microsoft\Windows\Something'}