GPO - Get GPO permission details

The below PowerShell script will export the permission details of all matching GPO to CSV file.


#Import Group Policy Module
Import-Module GroupPolicy

#Get current path
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path

# Define Variables
$MatchPattern = "TestGPO-"
$OutFile = $directorypath + "\Result.csv"
$OutFile
Set-Content $OutFile ""


$GPO=get-gpo -all | where {$_.displayname -match $MatchPattern} |foreach {

    $GPOName = $_.DisplayName;
   
    $GPOPerm= Get-GPPermissions $GPOName -All
    foreach($GPOtrustee in $GPOPerm)
    {
     $Result= $GPOName + "," + $GPOtrustee.Trustee.Name +","+ $GPOtrustee.Permission
     Write-Host $Result
     Add-Content $OutFile $Result
   
    }
   
 }

Comments

Post a Comment

Popular posts from this blog

SCCM Software Distribution Troubleshooting

Powershell - List AD Organizational Unit and GPOs linked to them

Troubleshooting System Center Endpoint Protection (SCEP) Client