-6

I need a PowerShell script to enable client side targeting and set a target group name for the computer by changing this registry key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate]
"TargetGroup"="<CUSTOMER_SHORT_NAME>;<SUBGROUPNAME>"
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129

1 Answers1

4

Server Fault is not a script writing service. However, you need to get some things clear first...

I need ... to enable client side targeting.

If you have a Windows AD Domain, use Group Policy instead. It's much more maintainable, because you won't need to run your script on every computer, but just move it to the correct OU.

Computer Configuration 
 |- Administrative Templates
  |- Windows Components
   |- Windows Update

has a policy Enable client-side targetting you can use for setting the group.

I need a power shell script ...

This would be a very basic PowerShell script for setting two to four registry keys: Setting the TargetGroup alone doesn't enable the targeting; TargetGroupEnabled does. You also need to specify the WSUS server in keys for both getting the updates and reporting the updates applied.

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate]
"WUServer"="https://wsusserver.example.com"
"WUStatusServer"="https://wsusserver.example.com"
"TargetGroup"="TargetGroupName"
"TargetGroupEnabled"=dword:00000001

Now you are ready to write the script for Updating or Adding Registry Key Value with PowerShell. Here's the script from the article, modified to update TargetGroupEnabled. Rest is homework.

$registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
$Name = "TargetGroupEnabled"
$value = "1"

IF(!(Test-Path $registryPath))
{
    New-Item -Path $registryPath -Force | Out-Null
    New-ItemProperty -Path $registryPath -Name $name -Value $value `
        -PropertyType DWORD -Force | Out-Null
}
ELSE
{
    New-ItemProperty -Path $registryPath -Name $name -Value $value `
        -PropertyType DWORD -Force | Out-Null
}
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • Thank You.The above registry changes are done for all entry through powershell and values are updated, But unable to see the changes under GP Edit > Windows Update. Even after restart of services and gpupdate. Could you please guide. – shubhranshu dash Apr 17 '18 at 07:23