Hi,
This is a way to do it :
Import-Module GroupPolicy
$GPOName = "YourGPOName"
$GPO = Get-GPO -Name $GPOName
# Define the lists of computers for each registry entry
$RegistryEntry1Computers = @("Computer1", "Computer2", "Computer3")
$RegistryEntry2Computers = @("Computer4", "Computer5", "Computer6")
# Add more lists for the other registry entries as needed
# Function to create an item-level targeting collection with OR logic for a list of computer names
function New-ComputerTargetingCollection ($ComputerList) {
$TargetingCollection = New-GPItemLevelTargetingCollection -Condition OR
foreach ($Computer in $ComputerList) {
$ComputerTargeting = New-GPItemLevelTargeting -HostName -IsEQ -Name $Computer
$TargetingCollection.Add($ComputerTargeting)
}
return $TargetingCollection
}
# Create the item-level targeting collections for the registry entries
$RegistryEntry1Targeting = New-ComputerTargetingCollection -ComputerList $RegistryEntry1Computers
$RegistryEntry2Targeting = New-ComputerTargetingCollection -ComputerList $RegistryEntry2Computers
# Add more targeting collections for the other registry entries as needed
# Function to apply the item-level targeting collection to the registry entry within the GPO
function Set-GPRegistryItemLevelTargeting ($GPO, $RegistryKeyPath, $TargetingCollection) {
$RegistryEntry = Get-GPRegistryValue -Guid $GPO.Id -Key $RegistryKeyPath
if ($RegistryEntry -ne $null) {
$RegistryEntry.ItemLevelTargeting = $TargetingCollection
Set-GPRegistryValue -Guid $GPO.Id -RegistryValue $RegistryEntry -TargetingCollection $TargetingCollection
}
}
# Apply the item-level targeting collections to the respective registry entries within the GPO
$RegistryKeyPath1 = "HKEY_LOCAL_MACHINE\Software\Example\RegEntry1"
$RegistryKeyPath2 = "HKEY_LOCAL_MACHINE\Software\Example\RegEntry2"
# Add more registry key paths for the other registry entries as needed
Set-GPRegistryItemLevelTargeting -GPO $GPO -RegistryKeyPath $RegistryKeyPath1 -TargetingCollection $RegistryEntry1Targeting
Set-GPRegistryItemLevelTargeting -GPO $GPO -RegistryKeyPath $RegistryKeyPath2 -TargetingCollection $RegistryEntry2Targeting
# Add more calls to Set-GPRegistryItemLevelTargeting for the other registry entries as needed