2016-01-21 40 views
1

不幸的是,我不太熟悉PowerShell,而我的Google技巧尚未解決我的問題。遞歸列出來自網絡共享和列表組成員的文件夾和子文件夾

到目前爲止,我有以下腳本:

Get-childitem \\network\share\ -recurse | where{$_.psiscontainer} | 
Get-Acl | % { 
    $path = $_.Path 
    $_.Access | % { 
     New-Object PSObject -Property @{ 
      Folder = $path.Replace("Microsoft.PowerShell.Core\FileSystem::","") 
      Access = $_.FileSystemRights 
      Control = $_.AccessControlType 
      User = $_.IdentityReference 
      Inheritance = $_.IsInherited 
      } 
     } 
    } | ? {-not $_.Inheritance} | export-csv output.csv -force 

哪些(部分)給了我下面的輸出:

User          Folder 
$DOMAIN\network_share_sub1_write   \\network\share\sub1 
$DOMAIN\network_share_sub1_read    \\network\share\sub1 
$DOMAIN\network_share_sub1_subsub1_write \\network\share\sub1\subsub1 
$DOMAIN\network_share_sub2_write   \\network\share\sub2 

這裏的問題是,我要回去看看各組看各個用戶。我想要的是這樣的:

User Permission Folder 
$User1 write  \\network\share\sub1 
$User2 read  \\network\share\sub1 
$User3 write  \\network\share\sub1\subsub1 
$User1 write  \\network\share\sub2 

是這樣的可能嗎? 在此先感謝。

+0

我不打算提出一個明確的答案,但我會用$ _。的IdentityReference在ACL和檢查AD一些AD命令行開關,看看他們是羣體,如果是的話,得到小組的成員。希望能讓你開始。 –

回答

0

我建議使用這個腳本https://jfrmilner.wordpress.com/2011/05/01/audit-ntfs-permissions-powershell-script/幫助了我很多,並根據您的選擇進行編輯。

例如,我只是想深入進去兩個層面,所以我改變線11的Get-PathPermissions.ps1的是:

$containers = Get-ChildItem -path $Path,$Path\*\* | ? {$_.psIscontainer -eq $true} 

此外,您可以將文件夾與Sort-Object Path進行排序,以便您從頂部到所需文件夾具有完整的層次結構(由深度指定)。比方說,如果你想要去的三個層次深,而不是兩個,它應該是這樣的Get-ChildItem -path $Path,$Path\*\*,$Path\*\*\*等..

1
Get-childitem \\network\share\ -recurse | where{$_.psiscontainer} | 
Get-Acl | % { 
    $path = $_.Path 
    $_.Access | % { 
     New-Object PSObject -Property @{ 
      Folder = $path.Replace("Microsoft.PowerShell.Core\FileSystem::","") 
      Access = $_.FileSystemRights 
      Control = $_.AccessControlType 
      User = $_.IdentityReference 
      Inheritance = $_.IsInherited 
      } 
     } 
    } | select-object -Property User, Access, Folder | export-csv output.csv -force 

選擇對象,物業用戶,訪問,文件夾
代碼將重新排列順序,你會看到你想要的。

User Permission Folder 
$User1 write  \\network\share\sub1 
$User2 read  \\network\share\sub1 
$User3 write  \\network\share\sub1\subsub1 
$User1 write  \\network\share\sub2 
相關問題