2016-11-22 2 views
0

다음은 코드입니다. 사용자를위한 디렉토리를 만들어야합니다. 디렉토리가 이미 존재하는 경우 ACL 부분을 건너 뛰는 방법에 대해 궁금합니다.디렉토리가 존재하는 경우 사용 권한 건너 뛰기

#Search AD for Elem Students 

$elem = Get-ADUser -Filter 'company -eq "1479"' 
$path = "\\hs-ss\students\elem" 
foreach ($user in $elem) 
{ 
    $Username = $User.SamAccountName 

    #Create user directory of Storage Server 

    New-Item -Path $path -Name $Username -ItemType "directory" -Force | Out-Null 
    $ACL = Get-Acl "$path\$Username" 
    $ACL.SetAccessRuleProtection($true, $false) 
    $ACL.Access | ForEach { [Void]$ACL.RemoveAccessRule($_) } 
    $ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("$NTDomain\Domain  Admins", "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow"))) 
    $ACL.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule("$NTDomain\$username", "Modify", "ContainerInherit, ObjectInherit", "None", "Allow"))) 
    Set-Acl "$Path\$username" $ACL 
} 

답변

1

점검 디렉토리가 존재하는 경우 :

if (-not (Test-Path -LiteralPath "$path\$Username" -Type Container)) { 
    ... 
} 
관련 문제