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
}