Set-GPOPermission.ps1

# Set-GPOPermission.ps1
Param($GPOName,
      $User,
      $Permission,
      [switch]$replace,
      [switch]$All,
      [switch]$verbose)

if($verbose){$verbosepreference = "continue"}
else{$erroractionpreference = "SilentlyContinue"}

if(!($GPOName -or $All))
{
    Write-Host "Please supply GPOName or -All to Set Permissions"
    return
}
. "$pwd\Set-GPEnvironment.ps1"

switch ($Permission)
{
    "Read"  {$Perm = $gpmConstants.permGPORead}
    "Apply" {$Perm = $gpmConstants.permGPOApply}
    "Edit"  {$Perm = $gpmConstants.permGPOEdit}
    "FC"    {$Perm = $gpmConstants.permGPOEditSecurityAndDelete}
    "None"  {$Perm = 0}
    Default {Write-Host
              '$Permission should be Read,Apply,Edit,FC, or None'
             return
            }
}

if($perm)
{
    $GPMPermission = $GPM.CreatePermission($User,$Perm,$false)
}

Write-Host " - Getting GPOs"
$GPOs = $gpmDomain.SearchGPOs($gpm.CreateSearchCriteria())

if($GPOName)
{
    $GPOs = $GPOs | Where{$_.DisplayName -like $GPOName}
}

foreach($gpo in $GPOs)
{
    Write-Host " + Processing $($Gpo.DisplayName)"
    $secInfo = $GPO.GetSecurityInfo()
    if($replace -or ($perm -eq 0))
    {
        Write-Host "   - Removing $User Permissions"
        $secInfo.RemoveTrustee($User)
    }
    if($perm -ne 0)
    {
        Write-Host "   - Adding Permissions [$Permission]"
        $secInfo.Add($GPMPermission)
    }
    Write-Host "   - Setting info on $($Gpo.DisplayName)"
    $GPO.SetSecurityInfo($secInfo)
}

Attachments:
 Set-GPOPermission.txt- Set-GPOPermission.ps1 script referenced in Chapter 11. Please change the file extension from .txt to .ps1.
 

Be a hero! Report a problem with this web page here

Event Calendar

Find out where and when Jeremy will be speaking next.

November 2008
SMTWTFS
1
2345678
9101112131415
16171819202122
23242526272829
30
Mon, Nov 10 - Thu, Nov 13
Windows Connections -- Vegas
It's WinConnections time! All sorts of great speeches this time. GP Troubleshooting, My Pre-Con, App-V 101. Will you be there?
www.winconnections.com
Mon, Nov 17 - Tue, Nov 18
Two-Day Intensive Group Policy Essentials Workshop (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a Two-Day Intensive Group Policy Essentials Workshop in Atlanta, GA !
Wed, Nov 19 - Thu, Nov 20
Two-Day "Group Policy 2.0" Catch-Up Workshop (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a Two-Day "Group Policy 2.0" Catch-Up Workshop in Atlanta, GA !
Fri, Nov 21 - Fri, Nov 21
One-Day Advanced Group Policy Workshop (XP/Vista Focused) (taught by Jeremy Moskowitz (Lead Instructor) - GPanswers.com / Moskowitz, Inc. )
 Final class of 2008.
This is a One-Day Advanced Group Policy Workshop (XP/Vista Focused) in Atlanta, GA !