2012-07-11 17 views
7

我已閱讀了許多關於此的帖子,但我仍然無法得到它。我以管理員身份運行此腳本,並創建所需的文件夾,但沒有設置適當的權限。任何幫助,將不勝感激。謝謝!PowerShell文件夾權限錯誤 - 無法翻譯部分或全部標識引用。

$Users = Get-Content "D:\New_Users.txt" 
ForEach ($user in $users) 
{ 
    $newPath = Join-Path "F:\Users" -childpath $user 
    New-Item $newPath -type directory 

    $UserObj = New-Object System.Security.Principal.NTAccount("DOMAIN",$user) 

    $acl = Get-Acl $newpath 
    $acl.SetAccessRuleProtection($True, $False) 
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("O1OAK\$user","AppendData,CreateDirectories,CreateFiles,DeleteSubdirectoriesAndFiles,ExecuteFile,ListDirectory,Modify,Read,ReadAndExecute,ReadAttributes,ReadData,ReadExtendedAttributes,ReadPermissions,Synchronize,Traverse,Write,WriteAttributes,WriteData,WriteExtendedAttributes","ContainerInherit, ObjectInherit","None","Allow") 
    $acl.SetAccessRule($accessRule) 
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("NT AUTHORITY\SYSTEM","FullControl","ContainerInherit, ObjectInherit","None","Allow") 
    $acl.SetAccessRule($accessRule) 
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("BUILTIN\Administrators","FullControl","ContainerInherit, ObjectInherit","None","Allow") 
    $acl.SetAccessRule($accessRule) 
    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("1OAK\$user","Delete","ContainerInherit, ObjectInherit","None","Allow") 
    $acl.removeAccessRule($accessRule) 
    $acl.SetOwner($UserObj) 
    $acl | Set-Acl $newpath 
} 

我得到的3個字符串中的第一個錯誤如下。我認爲這是最重要的,並會解決其他2

Exception calling "SetAccessRule" with "1" argument(s): "Some or all identity references could not be translated." 
At D:\DOMAIN\IT\IT Private\User Drives\user_folders.ps1:12 char:20 
+  $acl.SetAccessRule <<<< ($accessRule) 
    + CategoryInfo   : NotSpecified: (:) [], MethodInvocationException 
    + FullyQualifiedErrorId : DotNetMethodException 

我希望這不是一個重複的,我很抱歉,如果是這樣,我一直在讀了好幾個小時。謝謝!

+0

第1個$ accessRule有一個身份參數有一個域名'O1OAK'第4個'1OAK'。這是可行的嗎? – 2012-07-12 08:40:32

回答

15

的錯誤是非常自我解釋:Some or all identity references could not be translated.

這意味着無法找到該帳戶。所以你必須做的是驗證你的賬戶。由於您添加了4個ACE,因此您需要確定哪些是無效的。

最簡單的方法是使用ISE或PowerGUI逐行進行調試。

我用「NT AUTHORITY \ SYSTEM」和「BUILTIN \ Administrators」試過了你的代碼,所以問題出在"O1OAK\$user""1OAK\$user"。您的文本文件中可能有一個無效的帳戶。

+1

謝謝。那是一個愚蠢的錯誤。我發誓我整天都在讀它。我想這只是隨着時間的推移纔開始看起來正確。對不起,感謝您的時間。 – Siriss 2012-07-12 15:32:24

0

帶有用戶ID的gotch是AD截斷用戶名,因此具有長名稱「j_reallylongname」的用戶將具有被截斷的samid(安全帳戶管理器(SAM)帳戶名)。 (j_reallylong)

因此,在提取用戶名時,請確保在使用前驗證AD。

當我有了提示符時,所以我運行dsget查詢來獲取samid,然後使用它來構建身份引用。

相關問題