2

ユーザーのホーム ドライブからドメイン ユーザーを削除しようとすると、Powershell 3.0 で通常とは異なる状況が発生することがわかりました。その理由について何か考えがあるかどうかを確認したいと思います。

私がやろうとしていることを理解できるように疑似コード

 Create a new folder
 Grant User access to write their home drive
 Remove Inherited Permissions from folder
 Remove general access from all Domain Users

実際のコード (簡単にするためにエラー処理を削除しています)

$UserName = "auser"
$Path = "\\domain.com\user\users\" + $UserName
$UserIdentityReference = "DOMAIN\" + $UserName

$NewFolder = New-Item -ItemType directory -Path $Path

#Need to allow the user to write to the folder
$GrantUserAccesRule = New-Object System.Security.AccessControl.FileSystemAccessRule($UserIdentityReference, @("ListDirectory", "ReadData", "WriteData", "CreateFiles", "CreateDirectories", "AppendData", "ReadExtendedAttributes", "WriteExtendedAttributes", "Traverse", "ExecuteFile", "ReadAttributes", "WriteAttributes", "Write", "ReadPermissions", "Read", "ReadAndExecute", "Modify", "Synchronize"), "ContainerInherit,ObjectInherit", "None", "Allow")
$acl = Get-Acl $NewFolder
$acl.AddAccessRule($GrantUserAccesRule)
Set-Acl -aclobject $acl -Path $NewFolder

# Remove inheritence from parent folder.
$acl = Get-Acl $NewFolder
$acl.SetAccessRuleProtection($true,$true)
Set-Acl -aclobject $acl -Path $NewFolder

#Need to prevent any domain user from accessing the folder
$acl = Get-Acl $NewFolder
$RemoveDomainUsersACLRule = $acl | Select -ExpandProperty Access | where-object {$_.IdentityReference -eq $UserIdentityReference}
$acl.RemoveAccessRule($RemoveDomainUsersACLRule)
#ERROR OCCURS HERE
Set-Acl -aclobject $acl -Path $NewFolder

エラーは次のとおりです。

Set-Acl : The process does not possess the 'SeSecurityPrivilege' privilege which is required for this operation.
At line:4 char:3
+   Set-Acl -aclobject $acl -Path $NewFolder
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo          : PermissionDenied: (\\gifs.com\user\users\tautomation:String) [Set-Acl], PrivilegeNotHeldException
  + FullyQualifiedErrorId : System.Security.AccessControl.PrivilegeNotHeldException,Microsoft.PowerShell.Commands.SetAclCommand

奇妙なことに、SetAccessRuleProtection($true,$true) を実行するとすぐに、ロールを追加したり、追加したばかりのロールを削除したりできなくなります。

私が試したこと

  • SetAccessRuleProtection の前に行う限り、追加したロールを削除できます。

  • ファイル エクスプローラーから「Domain Users」グループを手動で削除すると機能します。

  • 昇格したユーザーとしてpowershellを実行しています。これは違いはありません

研究はすでに行われています: http://blogs.technet.com/b/josebda/archive/2010/11/12/how-to-handle-ntfs-folder-permissions-security-descriptors-and-acls- を読みました in-powershell.aspx

4

1 に答える 1

4

この Connect bugのように聞こえます。Set-Acl を使用する代わりに、ファイル/フォルダーに SetAccessControl() を使用することを常にお勧めします (Set-Acl にはファイルシステムに関する問題があります)。すべての Set-Acl 呼び出しを次のように変更します。

(Get-Item $NewFolder).SetAccessControl($acl)
于 2015-09-16T03:44:15.977 に答える