Set Registry Value for every user to include their Username

I need to set the key \Software\Microsoft\Windows\Run, value=OneDrive data="%LocalAppData%\Microsoft\OneDrive\OneDrive.exe /background" for every user on a machine. I’m not sure if I understand the Invoke-HKCURegistrySettingsForAllUsers function. Do I need to use Get-UserProfiles and try to loop through each of those, or is there a better way? If there is a good example please point me in the right direction?


Uncertain if you ever figured this out, but if the key is located under HKCU it would look something like this. I cannot confirm if this will work entirely but it’s worth testing and reporting back.

[scriptblock]$HKCURegistrySettings = {
    Set-RegistryKey -Key 'HKCU\Software\Microsoft\Windows\CurrentVersion\Run' -Name 'OneDrive' -Value "%LocalAppData%\Microsoft\OneDrive\OneDrive.exe /background"  -Type REG_SZ -SID $UserProfile.SID
    Invoke-HKCURegistrySettingsForAllUsers -RegistrySettings $HKCURegistrySettings


Go with active-setup

Thanks Kyle, that was the answer we ended up using. The reason we can’t use ActiveSetup is that it’s related to an app that needs the key updated prior to login.