Import-Module GroupPolicy
If you add the -Verbose switch to the command, you should see a list of all of the cmdlets available in that module.
$grp = "GPOAdministrators"
$level = "GpoEditDeleteModifySecurity"
Next, we will grab all Group Policy Objects that start with "china":
$gpos = get-gpo -All | where {$_.DisplayName -like "china*"}
Now that we have a complete list of GPOs that start with "china", we can go into each and set the permissions. To do this, we will go through each item in the array ($gpos) and grab the name of each GPO, and then use the set-GPPermissions cmdlet to give the security group rights on each:
foreach ($gpo in $gpos)
{
$gpname = $gpo.DisplayName
set-GPPermissions -Name $gpname -permissionlevel $level -TargetName $grp -targettype Group
}
PowerShell will now process each GPO as appropriate. The full script looks as follows:
Import-Module GroupPolicy
$grp = "GPOAdministrators"
$level = "GpoEditDeleteModifySecurity"
$gpos = get-gpo -All | where {$_.DisplayName -like "china*"}
foreach ($gpo in $gpos)
{
$gpname = $gpo.DisplayName
set-GPPermissions -Name $gpname -permissionlevel $level -TargetName $grp -targettype Group
}
get-help set-GPPermissions -full
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)