我正在開發一個腳本來比較兩個不同文件位置之間的訪問權限。我的問題類似於this question about System.Collections,因爲我將信息記錄到散列表,但它不以可讀方式打印到文件。如何將Powershell ACL信息以散列形式很好地打印到文件
這裏是我的代碼
Get-ChildItem -path $location1 -recurse | ForEach{$original_file_permissions[$_.name] = (Get-ACL $_.fullname).Access; Write-Host Parsing $_.fullname}
$original_file_permissions.getenumerator() | Format-Table | Out-File "U:\file_folder\sub_folder\original_file_permissions.txt
我的代碼分析文件的位置,使用Get-ACL方法來捕獲該文件或文件夾的訪問細節,把它作爲哈希表中的值,其中關鍵是文件或文件夾標題。然而,散列打印到的文件不打印確切的細節,它相反,打印,我相信,一個系統類?我不完全確定。
這裏是什麼文件看起來像
sys.a90 {System.Security.AccessControl.FileSystemAccessRule, System.Security.AccessControl.FileSystemAccessRule}
pickering-app_beta_02.hex {System.Security.AccessControl.FileSystemAccessRule, System.Security.AccessControl.FileSystemAccessRule}
release_notes.txt {System.Security.AccessControl.FileSystemAccessRule, System.Security.AccessControl.FileSystemAccessRule}
126037AA {System.Security.AccessControl.FileSystemAccessRule, System.Security.AccessControl.FileSystemAccessRule, System.Security.AccessControl.FileSystemAccessRule, System.Security.AccessControl.FileSystemAccessRule}
然而,當我運行PowerShell的終端相同的命令和訪問的關鍵,我感到我正在尋找的ACL信息。
PS C:\file_folder\sub_folder> $hash["126037AA"]
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : user123
IsInherited : True
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
FileSystemRights : FullControl
AccessControlType : Allow
IdentityReference : admin
IsInherited : True
InheritanceFlags : ContainerInherit, ObjectInherit
PropagationFlags : None
...
爲什麼會發生這種情況?我該如何做到這一點,以便哈希中的ACL細節是打印到文件的內容?
您需要訪問您要打印的成員,否則它會將對象類型打印到文件中。 – TheIncorrigible1
好吧,它打印對象類型。 .GetEnumerator()是否不訪問散列表的每個成員? – gsamerica
不,它與輸入'$ Hash'基本相同,除非你不能通過'.GetEnumerator()來訪問成員。「# – TheIncorrigible1