Преглед на файлове

Upload files to ''

Designed to backup permissions to typical directories that have unique permissions, then use icacls to reset permissions on C:, then restore the permissions on these special directories. This is currently a beta script, no errors are reported in Powershell ISE - Script Analyzer. Does need testing and refinement for professional usage.
nathan преди 1 година
родител
ревизия
13b09ee4e9
променени са 1 файла, в които са добавени 41 реда и са изтрити 0 реда
  1. 41
    0
      icaclsresetandbackuptest.ps1

+ 41
- 0
icaclsresetandbackuptest.ps1 Целия файл

@@ -0,0 +1,41 @@
1
+# Define the system folders to back up
2
+$SystemFolders = @( "Users", "Program Files", "Program Files (x86)", "ProgramData", "Windows"
3
+)
4
+
5
+# Loop through each system folder
6
+foreach ($Folder in $SystemFolders) { # Check if the folder exists
7
+    if (Test-Path -Path $Folder) {
8
+        # Save the permissions of the folder to an ACL file
9
+        & icacls $Folder /save "$Folder.acl" /t } }
10
+
11
+# Define the special folders to back up
12
+$SpecialFolders =@( "WindowsApps", "Program Files\\WindowsApps", "Program Files\\ModifiableWindowsApps", "Windows\\SystemApps", "Windows\\SysWOW64\\config\\systemprofile\\AppData\\Local\\Microsoft\\WindowsApps"
13
+
14
+)
15
+
16
+# Loop through each special folder
17
+foreach ($Folder in $SpecialFolders) { # Check if the folder exists
18
+    if (Test-Path -Path $Folder) {
19
+        # Save the permissions of the folder to an ACL file
20
+        & icacls $Folder /save "$Folder.acl" /t } }
21
+
22
+# Reset the permissions on C:
23
+& icacls C:\\ /reset /t
24
+
25
+# Loop through each special folder again
26
+foreach ($Folder in $SpecialFolders) {
27
+    # Check if the ACL file exists
28
+    if (Test-Path -Path "$Folder.acl") {
29
+        # Restore the permissions of the folder from the ACL file
30
+        & icacls C:\\ /restore "$Folder.acl"
31
+    }
32
+}
33
+
34
+# Loop through each special folder again
35
+foreach ($Folder in $SpecialFolders) {
36
+    # Check if the ACL file exists
37
+    if (Test-Path -Path "$Folder.acl") {
38
+        # Restore the permissions of the folder from the ACL file
39
+        & icacls C:\\ /restore "$Folder.acl"
40
+    }
41
+}

Powered by TurnKey Linux.