# Define the system folders to back up $SystemFolders = @( "Users", "Program Files", "Program Files (x86)", "ProgramData", "Windows" ) # Loop through each system folder foreach ($Folder in $SystemFolders) { # Check if the folder exists if (Test-Path -Path $Folder) { # Save the permissions of the folder to an ACL file & icacls $Folder /save "$Folder.acl" /t } } # Define the special folders to back up $SpecialFolders =@( "WindowsApps", "Program Files\\WindowsApps", "Program Files\\ModifiableWindowsApps", "Windows\\SystemApps", "Windows\\SysWOW64\\config\\systemprofile\\AppData\\Local\\Microsoft\\WindowsApps" ) # Loop through each special folder foreach ($Folder in $SpecialFolders) { # Check if the folder exists if (Test-Path -Path $Folder) { # Save the permissions of the folder to an ACL file & icacls $Folder /save "$Folder.acl" /t } } # Reset the permissions on C: & icacls C:\\ /reset /t # Loop through each special folder again foreach ($Folder in $SpecialFolders) { # Check if the ACL file exists if (Test-Path -Path "$Folder.acl") { # Restore the permissions of the folder from the ACL file & icacls C:\\ /restore "$Folder.acl" } } # Loop through each special folder again foreach ($Folder in $SpecialFolders) { # Check if the ACL file exists if (Test-Path -Path "$Folder.acl") { # Restore the permissions of the folder from the ACL file & icacls C:\\ /restore "$Folder.acl" } }