2017-12-14 39 views
0

와 UNC 경로에-ACL을 가져 PowerShell을.내가 <code>Get-Acl</code> cmdlet을 통해 UNC 경로에 대한 ACL을 확인하려고 공간

다음은 공백없이 로컬 파일 시스템이나 UNC 경로를 탐색 할 때 잘 작동합니다. 공백

UNC 경로에
$ou = 'OU=Security Groups,DC=mydomain,DC=local' 

$basepath = '\\mydomain\dfsroot' 

$filter = '*501*' 

Get-ADGroup -SearchBase $ou -Filter { Name -like $filter } | % { 
    $principle = $_.samAccountName 
    Get-ChildItem -LiteralPath $basepath -Recurse | % { 
     $path = $_.FullName 
     ($path | Get-Acl).Access.IdentityReference | % { if ($_.Value -match $principle) { Write-Host "$principle has rights to $path" }} 
    } 
} 

은 내가 "FileNotFoundException이"를 얻을 :

Get-Acl : \local501\dfsroot\docs\Accounting\Bankruptcy Files\NOTICE TO MEMBERSHIP RE-CHAPTER 11.pdf
At C:\Users\administrator.LOCAL501\Documents\IT Support Guys - (855) 4 IT GUYS\Files\find_paths_by_principle.ps1:11 char:18
+ ($path | Get-Acl).Access.IdentityReference | % { if ($_.Valu ...
+ ~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Acl],FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetAclCommand

누군가 나를 여기에 무슨 일이 일어나고 있는지 이해하는 데 도움이 수 있습니까?

감사합니다.

답변

0

그래서 코드는 조금 불필요하게 복잡하다.

If (-not (Test-Path -Path DFS:\)) 
{ New-PSDrive -Name DFS -PSProvider FileSystem -Root \\mydomain\dfsroot } 

$OU   = 'OU=Security Groups,DC=mydomain,DC=local' 
$Filter  = '*501*' 
$Principles = (Get-ADGroup -SearchBase $OU -Filter {Name -like $Filter}).samAccountName 
$Collection = @() 

ForEach ($Path in (Get-ChildItem -Path DFS:\ -Recurse -ErrorVariable +CustomERR)) 
{ 
    ## Using an array literal so items don't end up appended to one giant hashtable 
    $Collection += @(
     @{ Path = $Path.FullName 
      Acl = (Get-Acl -Path $Path.FullName).Access.IdentityReference.Value 
     } 
    ) 
} 

ForEach ($Principle in $Principles) 
{ 
    ForEach ($Item in $Collection) 
    { 
     If ($Item.Acl -contains $Principle) 
     { 
      Write-Host "'$Principle' has rights to '$($Item.Path)'" 
     } 
    } 
} 

편집 : 다음은 흐름을 이해하기 쉽게하고 공간에 오류가 밖으로 안되는 스크립트의 일부 최적화

+0

그 명령은 다음과 같습니다. Get-ChildItem : '\\ mydomain \ dfsroot \ demo \ path'경로의 일부를 찾을 수 없습니다. 줄에 : 1 문자 : 1 + -recurse '\\에 mydomain \의 dfsroot'- ChildItem을 얻기 + ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ReadError : (\\에 mydomain \ DFSR ... 모 \ 경로 : 문자열)은 Get-ChildItem을, DirectoryNotFoundException + FullyQualifiedErrorId : DirIOError, Microsoft.PowerShell.Commands.GetChildItemCommand –

+0

@ChristianGerlach'\\ mydomain \ dfsroot \ demo \ path'에 공백이 있습니까? 너무 일찍 실행하는 것은 매우 이상한 오류입니다. – TheIncorrigible1

+0

예. 나는 그것이 이상하다 동의합니다. –

0

이 무시했다! DFS 공유가 손상되었습니다. 파일 이름은 공백이있는 파일 이름입니다. 좋은 소식!