Skip to content

Instantly share code, notes, and snippets.

@IAmStoxe
Created January 24, 2024 21:05
Show Gist options
  • Save IAmStoxe/66e6b265d5eb18a00770274470040a7a to your computer and use it in GitHub Desktop.
Save IAmStoxe/66e6b265d5eb18a00770274470040a7a to your computer and use it in GitHub Desktop.

Group Policy Folder Redirection Analysis

This document provides an overview of the PowerShell script used to analyze Group Policy Objects (GPOs) for Folder Redirection settings and output the data for GPOs that are both enabled and linked within an Active Directory environment.

Script Overview

The script processes XML reports of GPOs, looking specifically for Folder Redirection settings. It compiles a list of GPOs that have Folder Redirection enabled and are actively linked to one or more Organizational Units (OUs).

Script Logic

Here's a step-by-step explanation of what the script does:

  1. Initialize Collection: A PowerShell array $FolderRedirections is initialized to store the redirection settings from each GPO.

  2. Iterate Through Reports: The script loops through each GPO report in the $Reports array.

  3. Extract GPO Information: For each GPO, the script extracts the name, link count, link paths, enabled status, and any Folder Redirection settings.

  4. Filter Enabled and Linked GPOs: The script includes a conditional check to ensure only GPOs that are enabled ($Enabled -eq 'true') and have at least one link ($LinkCount -gt 0) are processed.

  5. Compile Redirection Settings: For qualifying GPOs, Folder Redirection settings are extracted, including the known folder name and the target path to which the folder is redirected.

  6. Create Output Objects: A custom PowerShell object is created for each Folder Redirection setting and added to the $FolderRedirections array.

  7. Format and Output Data: The collected data is formatted into a table, displaying the relevant properties of each GPO with Folder Redirection.

Output Properties

The script outputs the following properties for each relevant GPO:

  • GPO: The name of the Group Policy Object.
  • LinkCount: The number of links or the number of OUs where the GPO is applied.
  • LinksTo: The actual paths of the OUs where the GPO is linked.
  • Enabled: Whether the GPO is enabled (true/false).
  • Folder: The known folder that is being redirected (e.g., Documents, Desktop).
  • Target: The target path for the redirected folder.
$KnownFolders = @{}
$KnownFolders.Add("{DE61D971-5EBC-4F02-A3A9-6C82895E5C04}" , "AddNewPrograms")
$KnownFolders.Add("{724EF170-A42D-4FEF-9F26-B60E846FBA4F}" , "AdminTools")
$KnownFolders.Add("{A520A1A4-1780-4FF6-BD18-167343C5AF16}" , "AppDataLow")
$KnownFolders.Add("{A305CE99-F527-492B-8B1A-7E76FA98D6E4}" , "AppUpdates")
$KnownFolders.Add("{9E52AB10-F80D-49DF-ACB8-4330F5687855}" , "CDBurning")
$KnownFolders.Add("{DF7266AC-9274-4867-8D55-3BD661DE872D}" , "ChangeRemovePrograms")
$KnownFolders.Add("{D0384E7D-BAC3-4797-8F14-CBA229B392B5}" , "CommonAdminTools")
$KnownFolders.Add("{C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D}" , "CommonOEMLinks")
$KnownFolders.Add("{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}" , "CommonPrograms")
$KnownFolders.Add("{A4115719-D62E-491D-AA7C-E74B8BE3B067}" , "CommonStartMenu")
$KnownFolders.Add("{82A5EA35-D9CD-47C5-9629-E15D2F714E6E}" , "CommonStartup")
$KnownFolders.Add("{B94237E7-57AC-4347-9151-B08C6C32D1F7}" , "CommonTemplates")
$KnownFolders.Add("{0AC0837C-BBF8-452A-850D-79D08E667CA7}" , "Computer")
$KnownFolders.Add("{4BFEFB45-347D-4006-A5BE-AC0CB0567192}" , "Conflict")
$KnownFolders.Add("{6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD}" , "Connections")
$KnownFolders.Add("{56784854-C6CB-462B-8169-88E350ACB882}" , "Contacts")
$KnownFolders.Add("{82A74AEB-AEB4-465C-A014-D097EE346D63}" , "ControlPanel")
$KnownFolders.Add("{2B0F765D-C0E9-4171-908E-08A611B84FF6}" , "Cookies")
$KnownFolders.Add("{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}" , "Desktop")
$KnownFolders.Add("{FDD39AD0-238F-46AF-ADB4-6C85480369C7}" , "Documents")
$KnownFolders.Add("{374DE290-123F-4565-9164-39C4925E467B}" , "Downloads")
$KnownFolders.Add("{1777F761-68AD-4D8A-87BD-30B759FA33DD}" , "Favorites")
$KnownFolders.Add("{FD228CB7-AE11-4AE3-864C-16F3910AB8FE}" , "Fonts")
$KnownFolders.Add("{CAC52C1A-B53D-4EDC-92D7-6B2E8AC19434}" , "Games")
$KnownFolders.Add("{054FAE61-4DD8-4787-80B6-090220C4B700}" , "GameTasks")
$KnownFolders.Add("{D9DC8A3B-B784-432E-A781-5A1130A75963}" , "History")
$KnownFolders.Add("{4D9F7874-4E0C-4904-967B-40B0D20C3E4B}" , "Internet")
$KnownFolders.Add("{352481E8-33BE-4251-BA85-6007CAEDCF9D}" , "InternetCache")
$KnownFolders.Add("{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}" , "Links")
$KnownFolders.Add("{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}" , "LocalAppData")
$KnownFolders.Add("{2A00375E-224C-49DE-B8D1-440DF7EF3DDC}" , "LocalizedResourcesDir")
$KnownFolders.Add("{4BD8D571-6D19-48D3-BE97-422220080E43}" , "Music")
$KnownFolders.Add("{C5ABBF53-E17F-4121-8900-86626FC2C973}" , "NetHood")
$KnownFolders.Add("{D20BEEC4-5CA8-4905-AE3B-BF251EA09B53}" , "Network")
$KnownFolders.Add("{31C0DD25-9439-4F12-BF41-7FF4EDA38722}" , "Objects3D")
$KnownFolders.Add("{2C36C0AA-5812-4B87-BFD0-4CD0DFB19B39}" , "OriginalImages")
$KnownFolders.Add("{69D2CF90-FC33-4FB7-9A0C-EBB0F0FCB43C}" , "PhotoAlbums")
$KnownFolders.Add("{33E28130-4E1E-4676-835A-98395C3BC3BB}" , "Pictures")
$KnownFolders.Add("{DE92C1C7-837F-4F69-A3BB-86E631204A23}" , "Playlists")
$KnownFolders.Add("{76FC4E2D-D6AD-4519-A663-37BD56068185}" , "Printers")
$KnownFolders.Add("{9274BD8D-CFD1-41C3-B35E-B13F55A758F4}" , "PrintHood")
$KnownFolders.Add("{5E6C858F-0E22-4760-9AFE-EA3317B67173}" , "Profile")
$KnownFolders.Add("{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}" , "ProgramData")
$KnownFolders.Add("{905E63B6-C1BF-494E-B29C-65B732D3D21A}" , "ProgramFiles")
$KnownFolders.Add("{F7F1ED05-9F6D-47A2-AAAE-29D317C6F066}" , "ProgramFilesCommon")
$KnownFolders.Add("{6365D5A7-0F0D-45E5-87F6-0DA56B6A4F7D}" , "ProgramFilesCommonX64")
$KnownFolders.Add("{DE974D24-D9C6-4D3E-BF91-F4455120B917}" , "ProgramFilesCommonX86")
$KnownFolders.Add("{6D809377-6AF0-444B-8957-A3773F02200E}" , "ProgramFilesX64")
$KnownFolders.Add("{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}" , "ProgramFilesX86")
$KnownFolders.Add("{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}" , "Programs")
$KnownFolders.Add("{DFDF76A2-C82A-4D63-906A-5644AC457385}" , "Public")
$KnownFolders.Add("{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}" , "PublicDesktop")
$KnownFolders.Add("{ED4824AF-DCE4-45A8-81E2-FC7965083634}" , "PublicDocuments")
$KnownFolders.Add("{3D644C9B-1FB8-4F30-9B45-F670235F79C0}" , "PublicDownloads")
$KnownFolders.Add("{DEBF2536-E1A8-4C59-B6A2-414586476AEA}" , "PublicGameTasks")
$KnownFolders.Add("{3214FAB5-9757-4298-BB61-92A9DEAA44FF}" , "PublicMusic")
$KnownFolders.Add("{B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}" , "PublicPictures")
$KnownFolders.Add("{2400183A-6185-49FB-A2D8-4A392A602BA3}" , "PublicVideos")
$KnownFolders.Add("{52A4F021-7B75-48A9-9F6B-4B87A210BC8F}" , "QuickLaunch")
$KnownFolders.Add("{AE50C081-EBD2-438A-8655-8A092E34987A}" , "Recent")
$KnownFolders.Add("{BD85E001-112E-431E-983B-7B15AC09FFF1}" , "RecordedTV")
$KnownFolders.Add("{B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC}" , "RecycleBin")
$KnownFolders.Add("{8AD10C31-2ADB-4296-A8F7-E4701232C972}" , "ResourceDir")
$KnownFolders.Add("{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}" , "RoamingAppData")
$KnownFolders.Add("{B250C668-F57D-4EE1-A63C-290EE7D1AA1F}" , "SampleMusic")
$KnownFolders.Add("{C4900540-2379-4C75-844B-64E6FAF8716B}" , "SamplePictures")
$KnownFolders.Add("{15CA69B3-30EE-49C1-ACE1-6B5EC372AFB5}" , "SamplePlaylists")
$KnownFolders.Add("{859EAD94-2E85-48AD-A71A-0969CB56A6CD}" , "SampleVideos")
$KnownFolders.Add("{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}" , "SavedGames")
$KnownFolders.Add("{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}" , "SavedSearches")
$KnownFolders.Add("{EE32E446-31CA-4ABA-814F-A5EBD2FD6D5E}" , "SEARCH_CSC")
$KnownFolders.Add("{98EC0E18-2098-4D44-8644-66979315A281}" , "SEARCH_MAPI")
$KnownFolders.Add("{190337D1-B8CA-4121-A639-6D472D16972A}" , "SearchHome")
$KnownFolders.Add("{8983036C-27C0-404B-8F08-102D10DCFD74}" , "SendTo")
$KnownFolders.Add("{7B396E54-9EC5-4300-BE0A-2482EBAE1A26}" , "SidebarDefaultParts")
$KnownFolders.Add("{A75D362E-50FC-4FB7-AC2C-A8BEAA314493}" , "SidebarParts")
$KnownFolders.Add("{625B53C3-AB48-4EC1-BA1F-A1EF4146FC19}" , "StartMenu")
$KnownFolders.Add("{B97D20BB-F46A-4C97-BA10-5E3608430854}" , "Startup")
$KnownFolders.Add("{43668BF8-C14E-49B2-97C9-747784D784B7}" , "SyncManager")
$KnownFolders.Add("{289A9A43-BE44-4057-A41B-587A76D7E7F9}" , "SyncResults")
$KnownFolders.Add("{0F214138-B1D3-4A90-BBA9-27CBC0C5389A}" , "SyncSetup")
$KnownFolders.Add("{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}" , "System")
$KnownFolders.Add("{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}" , "SystemX86")
$KnownFolders.Add("{A63293E8-664E-48DB-A079-DF759E0509F7}" , "Templates")
$KnownFolders.Add("{5B3749AD-B49F-49C1-83EB-15370FBD4882}" , "TreeProperties")
$KnownFolders.Add("{0762D272-C50A-4BB0-A382-697DCD729B80}" , "UserProfiles")
$KnownFolders.Add("{F3CE0F7C-4901-4ACC-8648-D5D44B04EF8F}" , "UsersFiles")
$KnownFolders.Add("{18989B1D-99B5-455B-841C-AB7C74E4DDFC}" , "Videos")
$KnownFolders.Add("{F38BF404-1D43-42F2-9305-67DE0B28FC23}" , "Windows")
$Reports = Get-GPO -All | Get-GPOReport -ReportType Xml
$FolderRedirections = @()
# Parse each report and extract Folder Redirection settings
ForEach ($Report In $Reports) {
$GPO = ([xml]$Report).GPO
$LinkCount = ([string[]]$GPO.LinksTo).Count
$LinksTo = ($GPO.LinksTo.SOMPath) -join ", "
$Enabled = $GPO.User.Enabled
if ($Enabled -eq 'true' -and $LinkCount -gt 0) {
foreach ($ExtensionData in $GPO.User.ExtensionData) {
if ($ExtensionData.Name -eq "Folder Redirection") {
foreach ($Redirection in $ExtensionData.Extension.Folder) {
$FolderName = $KnownFolders[$Redirection.Id]
if ($FolderName) {
$FolderRedirection = New-Object PSObject -Property @{
GPO = $GPO.Name
LinkCount = $LinkCount
LinksTo = $LinksTo
Enabled = $Enabled
Folder = $FolderName
Target = $Redirection.Location.DestinationPath
}
$FolderRedirections += $FolderRedirection
}
}
}
}
}
}
# Output the collected folder redirection data for enabled and linked GPOs
$FolderRedirections | Format-Table GPO, LinkCount, LinksTo, Enabled, Folder, Target -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment