powershell 스크립트에서 각각의 사용 권한을 가진 폴더 목록을 반복적으로 가져 오는 중이지만 재귀 부분이 발생할 경우 출력 문자열은 폴더 구조를 계속 인쇄합니다.Powershell에서 폴더 및 사용 권한 얻기
나는 C : \ temp \ folder라는 폴더를 가지고 있는데, 그 폴더 안에는 빈 폴더 C : \ temp \ folder1과 C : \ temp \ folder2가있다. 내 스크립트를 출력은 다음과 같습니다 나는 가독성
C:\temp
C:\temp\folder1
C:\temp
C:\temp\folder2
에 대한 사용 권한을 떠난
나는 이것이 내가 그들의 권한이있는 폴더 목록을 원하는 다음 경우 발생하지 않으 하위 폴더에 대한 사용 권한이 다른 경우 해당 폴더의 하위 폴더를 가져옵니다. 이것은 내가 어디에도 가지 않기 때문에 그것을보기 위해 신선한 쌍둥이가 필요하다고 생각하는 현관과는 별도로 작동합니다.
사전에 도움을 주셔서 감사합니다
,샘
CODE :
Add-Type -AssemblyName System.Windows.Forms
Import-Module ActiveDirectory
$info = ""
$OutputString
$step = 0
function DisplayForm{
#Some GUI code
#$textBox takes in the base folder from the user
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$baseFolder = $textBox.Text
$ParentProperties = (Get-Acl $baseFolder).Access| Select-Object -ExpandProperty IdentityReference
$OutputString = $OutputString + $baseFolder + "`r`n" + $ParentProperties + "`r`n`r`n"
$ChildFolders = Get-ChildItem $baseFolder | where {$_.Attributes -eq 'Directory'}
FindPriorities($baseFolder)
$info = "SAVED TO FOLDER"
outputList
}
}
function FindPriorities{
param($fileName)
$ChildFolders = Get-ChildItem $fileName | where {$_.Attributes -eq 'Directory'}
$step = $step + 1
$TempString = ""
foreach ($folder in $ChildFolders){
$child = $fileName + "\\" + $folder.name
$ParentProperties = (Get-Acl $fileName).Access| Select-Object -ExpandProperty IdentityReference
$ChildProperties = (Get-Acl $child).Access| Select-Object -ExpandProperty IdentityReference
$parentString=""
foreach ($p in $ParentProperties){
$parentString= $parentString + $p
}
$childString=""
foreach ($c in $childProperties){
$childString = $childString + $c
}
if($childString -ne $parentString){
$OutputString = $OutputString + $child + "`r`n" + $ChildProperties + "`r`n`r`n"
FindPriorities ($child)
}else{
$OutputString = $OutputString + $child + "`r`n" + $ChildProperties + "`r`n`r`n"
}
}
}
function outputList{
$OutputString
}
DisplayForm
당신은 그것 모두가 두 번 실행되지 않도록 FindPriorities''에서의 DisplayForm''에서 같은 foreach는 코드가 있습니다. ('foreach ($ ChildFolders의 $ 폴더) {...}'). 당신은 또한'DisplayForm' 함수의 끝에서'DisplayForm'을 다시 호출합니다. – Richard
네, 그것은 기본 폴더에있는 서브 폴더들에 대한 것입니다, 그리고 다른 허가권을 가진 것이 있다면 그것으로 들어가서 서브 폴더를 찾습니다 –
- -folder1 ----------- 폴더 2 (같은 사용 권한) ----------- 폴더 3 (다른 사용 권한) ----------- --------------------------- 폴더 4 ...... 등등. 난 항상 돌아와서 기본 폴더에있는 나머지 폴더를 확인해 봤어. 내가 이걸 좋아하는 이유 야. –