2017-10-12 150 views
1

我寫了一個腳本來給我一個特定路徑及其所有子目錄的訪問ACL,並將它放在一個.txt文件中,但我需要另一種格式來創建一個數據庫,使其更易於查看和訪問。如何以某種格式獲取FileSystemRights?

輸出

部分看起來是這樣的:

 
Fullname S   FileSystemRights S AccessControlType 
----------   ------------------ ------------------ 
C:\temp ; ReadAndExecute, Synchronize ;    Allow; 

所以我需要輸出的樣子是這樣的:

 
Fullname S FileSystemRights S AccessControlType 
---------- ------------------ ------------------ 
C:\temp ; ReadAndExecute ;    Allow; 
C:\temp ; Synchronize ;    Allow; 

正如你可以看到我需要在個人權利個別的線路,而不是堆疊在一起

什麼我迄今所做的看起來是下面的,也許它可以幫助(我離開了那些不重要的東西):

(Get-Acl $TestPath).Access | 
    Format-Table -AutoSize -HideTableHeaders @{L="Fullname";E={$TestPath}}, 
     @{L="S";E={";"}}, FileSystemRights, 
     @{L="S";E={";"}}, AccessControlType, 
     @{L="S";E={";"}}, IdentityReference, 
     @{L="S";E={";"}}, IsInherited, 
     @{L="S";E={";"}}, InheritanceFlags, 
     @{L="S";E={";"}}, PropagationFlags | 
    Out-File $Out -Append -Width 500 

function RecDirs { 
    $d = $Args[0] 
    $AktRec++ 
    $dirs = dir $d | where {$_.PsIsContainer} 
    if ($AktRec -lt 3) { 
     foreach($di in $dirs) { 
      if ($di.FullName -ne $null) { 
       (Get-Acl $di.Fullname).Access | 
        Format-Table -AutoSize -HideTableHeaders @{L="Fullname";E={$di.FullName}}, 
         @{L="S";E={";"}}, FileSystemRights, 
         @{L="S";E={";"}}, AccessControlType, 
         @{L="S";E={";"}}, IdentityReference, 
         @{L="S";E={";"}}, IsInherited, 
         @{L="S";E={";"}}, InheritanceFlags, 
         @{L="S";E={";"}}, PropagationFlags | 
        Out-File $Out -Append -Width 500 
      } 
      RecDirs($di.Fullname) 
     } 
    } 
} 

RecDirs($TestPath) 
+2

看一看export-csv – guiwhatsthat

回答

2

斯普利特在逗號和每個元件輸出一行FileSystemRights財產。並且您肯定希望Export-Csv用於編寫輸出文件。

(Get-Acl $di.Fullname).Access | ForEach-Object { 
    foreach ($val in ($_.FileSystemRights -split ', ')) { 
     $_ | Select-Object @{n='Fullname';e={$di.FullName}}, 
      @{n='FileSystemRights';e={$val}}, AccessControlType, 
      IdentityReference, IsInherited, InheritanceFlags, 
      PropagationFlags 
    } 
} | Export-Csv $Out -NoType -Append 
+0

很好的答案,非常感謝! –