use*_*880 5 powershell folder-permissions
我正在做一个powershell脚本,它在AD中创建新的域用户帐户,并在文件服务器中创建具有相关权限的主目录.
我的问题是我无法获得权限设置.
在下面的代码中,my_fileServer是文件服务器名称; sso表示单点登录ID,在下面的测试代码中设置为"user9999".
任何帮助是极大的赞赏!
Set-Variable homeDir -option Constant -value "\\my_fileServer\Users"
Set-Variable sso -option Constant -value "user9999"
# If the folder for the user does not exist, make a new one and set the correct permissions.
if ( (Test-Path "$homeDir\$sso") -eq $false)
{
try
{
$NewFolder = New-Item -Path $homeDir -Name $sso -ItemType "Directory"
$Rights = [System.Security.AccessControl.FileSystemRights]"FullControl,Modify,ReadAndExecute,ListDirectory,Read,Write"
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType =[System.Security.AccessControl.AccessControlType]::Allow
$objUser = New-Object System.Security.Principal.NTAccount "my_full_domain_name\$sso"
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule `
($objUser, $Rights, $InheritanceFlag, $PropagationFlag, $objType)
$ACL = get-acl -Path $NewFolder
$ACL.AddAccessRule($objACE)
$objReturn = Set-ACL -Path "$homeDir\$sso" -AclObject $ACL
$objReturn
}
catch
{
$msg = $_
$msg
}
}
Run Code Online (Sandbox Code Playgroud)
主文件夹创建正常,但是当我检查用户的权限时,没有勾选任何框.

问题是你的不干涉.您不允许在子文件夹和文件(他在其文件夹中拥有的项目)上继承权限.这就是您在基本安全窗口中看不到权限(仅"特殊权限")的原因.如果您打开"高级安全设置",您将看到用户完全控制OVER THIS文件夹,而不是内容.只要您为CREATOR OWNER添加权限(具有继承),以便所有者可以访问项目,我认为您会没事的.但是,您现在可以像这样修复它:
$InheritanceFlag = @([System.Security.AccessControl.InheritanceFlags]::ContainerInherit,[System.Security.AccessControl.InheritanceFlags]::ObjectInherit)
Run Code Online (Sandbox Code Playgroud)
除非有特殊要求,否则您应该授予用户对其文件夹的完全访问权限(完全继承).具有固定继承的完整解决方案(我还清理了您的Set-ACL路径并删除了不必要的返回对象):
try
{
$NewFolder = New-Item -Path $homeDir -Name $sso -ItemType "Directory"
$Rights = [System.Security.AccessControl.FileSystemRights]"FullControl,Modify,ReadAndExecute,ListDirectory,Read,Write"
$InheritanceFlag = @([System.Security.AccessControl.InheritanceFlags]::ContainerInherit,[System.Security.AccessControl.InheritanceFlags]::ObjectInherit)
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType =[System.Security.AccessControl.AccessControlType]::Allow
$objUser = New-Object System.Security.Principal.NTAccount "my_full_domain_name\$sso"
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule `
($objUser, $Rights, $InheritanceFlag, $PropagationFlag, $objType)
$ACL = Get-Acl -Path $NewFolder
$ACL.AddAccessRule($objACE)
Set-ACL -Path $NewFolder.FullName -AclObject $ACL
}
Run Code Online (Sandbox Code Playgroud)