Link to home
Start Free TrialLog in
Avatar of Len Kally
Len KallyFlag for United States of America

asked on

How can I add items in the registry via powershell?

I want to change a setting in the local GP of a bunch of machines:  Computer Configuration > Administrative Templates > Control Panel > Regional and Language Options > Block clean-up of unused language packs.  

It is in the local Group policy but it is not in the registry.  

It is NOT in the registry on a Windows 10 v1809 Enterprise Edition .  In the registry it only shows:  HKLM\Software\Policies\Microsoft.   After that there is no Control Panel\International

Can I add this manually in the registry:
Key: HKLM\Software\Policies\Microsoft\Control Panel\International

Value: blockCleanupOfUnusedPreinstalledLangpacks

Enable: 1

This machine is not part of a domain.  It is in a work group.


If I can does anyone know how to do it via PowerShell Script?

thanks
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Len Kally

ASKER

It is not enabled in group policy.   This is going out to 200 machines, I want to enable it.    Will your script do that, enable it.

That is what is confusing to me, the registry setting only is:  HKLM:\Software\Policies\Microsoft and I want to enable this policy.   Will your script to this from what I see, it should under 'New-Item.

Thanks


Avatar of oBdA
oBdA

The registry key is "HKLM:\Software\Policies\Microsoft\Control Panel\International", the value name is BlockCleanupOfUnusedPreinstalledLangPacks, the type is REG_DWORD, the value is 1.
This is exactly what the script will do.

Block clean-up of unused language packs
https://getadmx.com/?Category=Windows_10_2016&Policy=Microsoft.Policies.Globalization::BlockCleanupOfUnusedPreinstalledLangPacks

Another possibility that works both in Batch and PS is reg.exe:
reg.exe add "HKLM\Software\Policies\Microsoft\Control Panel\International" /v BlockCleanupOfUnusedPreinstalledLangPacks /t REG_DWORD /d 1 /f

Open in new window

I tried it and it worked added necessary setting to the registry but it did not change the Local Group policy settings.   I ran gpupdate
Because the group policy has its own database where it stores its settings. The GP Editor does not read its settings from the registry.
When you enable the policy in the GP Editor, it will write to the registry, but that's a one-way street.
I thought Administrative templates are registry settings?  And you can change the local group policy via a registry setting.

When I research on controlling the LGPO, it says find it's associated registry setting.    Then there is no way to change this LGPO

Thanks
The local group policy processing will write the settings it finds in its database to the registry, where the respective components that use these policies will read them.
That is all.
You can not change the local GPO's database by writing to the registry.
If the (manually created) registry setting is there, it will work exactly the same was as if it would have been set by a GPO.
wow thanks you been a real help, this is awesome
To "teach" you even more: you shouldn't need to write to the registry. Use GPOs and this gets set and gets set repeatedly (in case someone managed to delete that value). You give confusing info about GPO usage, since 1st you write
"It is in the local Group policy"
then you write
"It is not enabled in group policy"
as if you see that you can configure it, but simply don't do it. Why is that?

Use the domain policy to configure this and not scripts.

@McKnife,
He can't use a domain policy:

This machine is not part of a domain.  It is in a work group.
Then I missed that important part, sorry.
Let me clarify,  in the  local GP on the machine I am testing:  Computer Configuration > Administrative Templates > Control Panel > Regional and Language Options > Block clean-up of unused language packs
You either enable it or disable it.  

When I go to the registry of that machine it only shows part of the LGPO:
In the registry it only shows:  HKLM\Software\Policies\Microsoft.   After that there is no Control Panel\International

I am asking since Administrative Templates are basically Registry setting, why isn't this LGPO not in the registry.  

This is what I looked at, and why does the registry have International & the LPGO does not
https://www.exitcodezero.ch/2018/08/16/gpo-block-clean-upofunusedlp/ 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I noticed with this LGPO, if it is 'enable'  the full registry path does shows up in the registry.
User generated image


If you disable the LGPO,  the full path does not show up in the registry:
User generated image
Will it be enabled if I set the registry via powershell script.    
This is an image you cannot manually enable the GPO by hand.  Thx
Please keep your terminology straight.
If you disable the policy, the key will still show up in the registry, and the value for BlockCleanupOfUnusedPreinstalledLangPacks will be 0.
The key will only disappear if you set the policy to "Not configured".
This is a big difference.

And for the third time: the group policy has its own database (C:\Windows\System32\GroupPolicy\Machine\Registry.pol).
The GP processing that takes place based on the .pol file will only make sure that the registry keys defined in said file will be set.
But when you open the GP Editor, it does not care which keys do exist or not exist in the registry. It will only show you what's configured in its own database.
A manual change in the registry will never be reflected in the GP Editor, full stop.