2014-06-25 27 views
1

我有一個腳本,用於檢查文件夾中的ACL權限並將它們寫入CSV文件。我想繼承當輸出出來是這樣的:使用數組獲取ACL子文件夾

Allow Full Control, this folder, subfolders and files (Inherited) 

目前其唯一的輸出是:

Allow FullControl, (Inherited) 

有人可以告訴我,請我只是想失蹤文字顯示:

$RootPath = "C:\" 

$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true} 

$isInherited = @{ 
    $true = 'Inherited' 
    $false = 'Not Inherited' 
} 

$inheritance = @{ 
    0 = 'files only' 
    1 = 'this folder and subfolders' 
    2 = 'this folder and files' 
    3 = 'subfolders and files' 
} 

$fldr = $Folder.FullName 

$Folders | % { 
    $fldr = $_.FullName 
    Get-Acl $fldr | select -Expand Access | 
     select @{n='Account';e={$_.IdentityReference}}, 
       @{n='Ace String';e={"{0} {1}, {2} ({3})" -f $_.AccessControlType, 
       $_.FileSystemRights, $inheritance[$_.InheritanceFlags], 
       $isInherited[$_.IsInherited]}}, 
       @{n='Object Path';e={$fldr}} | 
     ConvertTo-Csv -NoTypeInformation | 
     Select -Skip 1 | % {$_ -replace '"', ""} | 
     Out-File $OutFile -Force -Encoding ascii -Append 
} 

回答

2

在檢查對象System.Security.AccessControl.InheritanceFlags

TypeName: System.Security.AccessControl.InheritanceFlags 

Name  MemberType Definition 
----  ---------- ---------- 
CompareTo Method  int CompareTo(System.Object target) 
Equals  Method  bool Equals(System.Object obj) 
GetHashCode Method  int GetHashCode() 
GetType  Method  type GetType() 
GetTypeCode Method  System.TypeCode GetTypeCode() 
ToString Method  string ToString(), string ToString(string format, System.IFormatProvider provider), string To... 
value__  Property System.Int32 value__ {get;set;} 

它看起來物體有value__屬性。因此,變線

$_.FileSystemRights, $inheritance[$_.InheritanceFlags], 

$_.FileSystemRights, $inheritance[$_.InheritanceFlags.value__], 

這將正確地傳遞[int]類型的參數來$inheritance哈希值。

+0

謝謝,自從昨天以來,這一直使我頭痛。 – user3772927

相關問題