如何在文件夹安全性选项卡中添加用户

时间:2014-10-23 10:40:45

标签: powershell

大家好我有一个共享文件夹,我已经给予了以下权限

net share $NetworkSharePath  '/Grant:Administrators,FULL' '/Grant:IIS_IUSRS,FULL' | out-null

但是这只会在共享权限选项卡上创建用户我想在安全选项卡中添加IIS用户,但是不知道如何做到这一点

$Networkshare_Name = 'Media'
$NetworkShare_Path = 'Media=C:\_Projects\mediaFolder'
net share $NetworkSharePath  '/Grant:Administrators,FULL' '/Grant:IIS_IUSRS,FULL' | out-null


    $acl = Get-Acl $NetworkSharePath
    $rule = New-Object   
    System.Security.AccessControl.FileSystemAccessRule("IIS_IUSRS","FullControl",   
    "ContainerInherit,ObjectInherit", "None", "Allow")  

    $acl.AddAccessRule($rule)
    Set-Acl $NetworkSharePath $acl

这仍然没有运气

    $folder = "C:\_Projects\mediaFolder"
    $acl = Get-Acl $folder
    $permission = "IIS_IUSRS","FullControl","Allow"
    $rule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
    $acl.AddAccessRule($rule)
    Set-Acl $folder $acl

1 个答案:

答案 0 :(得分:3)

$acl = Get-Acl $NetworkSharePath
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acl.AddAccessRule($rule)
Set-Acl $NetworkSharePath $acl